Skip to content

Good practice on how to create Input files for tests

Roman Ivanov edited this page Mar 28, 2021 · 8 revisions

Required: Each test method should have unique Input file Input file should have config be printed in comment above a class name of Input file related line with violations should be marked by trailing comment "// violation". it is ok if Input files are same by java content and differentiate by comments only.

Example of good Input file - https://github.com/checkstyle/checkstyle/blob/7190c47ca5515ad8cb827bc4065ae7664d2766c1/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/naming/recordcomponentname/InputRecordComponentNameLowercase.java

Test class - https://github.com/checkstyle/checkstyle/blob/7190c47ca5515ad8cb827bc4065ae7664d2766c1/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/RecordComponentNameCheckTest.java#L81

more reasons on why it matter are at: https://github.com/checkstyle/checkstyle/wiki/Checkstyle-GSoC-2021-Project-Ideas#project-name-adaptation-of-behavior-driven-development-ideas-for-testing-of-source-code-validation-algorithms

File https://github.com/checkstyle/checkstyle/blob/master/config/checkstyle_input_suppressions.xml needs to be updated to have no reference to Check input files

Very rough list of Test files that need to be updated (there should be separate issue for each file):

✔ ~/java/github/romani/checkstyle/src/test/java/com/puppycrawl/tools/checkstyle/checks [master|✔] 
$ grep -ER "Path\(\"Input.*.java\"\)" | uniq -d | cut -d ' ' -f 1 | uniq
OuterTypeFilenameCheckTest.java:
FinalParametersCheckTest.java:
regexp/RegexpMultilineCheckTest.java:
regexp/RegexpCheckTest.java:
regexp/RegexpOnFilenameCheckTest.java:
regexp/RegexpSinglelineCheckTest.java:
regexp/RegexpSinglelineJavaCheckTest.java:
naming/CatchParameterNameCheckTest.java:
naming/TypeNameCheckTest.java:
naming/InterfaceTypeParameterNameCheckTest.java:
naming/ParameterNameCheckTest.java:
naming/PackageNameCheckTest.java:
naming/StaticVariableNameCheckTest.java:
naming/MethodTypeParameterNameCheckTest.java:
naming/ClassTypeParameterNameCheckTest.java:
naming/AbbreviationAsWordInNameCheckTest.java:
naming/MethodNameCheckTest.java:
naming/LocalFinalVariableNameCheckTest.java:
naming/AbstractClassNameCheckTest.java:
naming/MemberNameCheckTest.java:
naming/ConstantNameCheckTest.java:
metrics/CyclomaticComplexityCheckTest.java:
metrics/JavaNCSSCheckTest.java:
metrics/ClassDataAbstractionCouplingCheckTest.java:
metrics/ClassFanOutComplexityCheckTest.java:
metrics/BooleanExpressionComplexityCheckTest.java:
sizes/OuterTypeNumberCheckTest.java:
sizes/MethodCountCheckTest.java:
sizes/FileLengthCheckTest.java:
sizes/ParameterNumberCheckTest.java:
sizes/MethodLengthCheckTest.java:
sizes/AnonInnerLengthCheckTest.java:
sizes/ExecutableStatementCountCheckTest.java:
sizes/LineLengthCheckTest.java:
modifier/InterfaceMemberImpliedModifierCheckTest.java:
design/InterfaceIsTypeCheckTest.java:
design/ThrowsCountCheckTest.java:
design/InnerTypeLastCheckTest.java:
design/VisibilityModifierCheckTest.java:
indentation/IndentationCheckTest.java:
AvoidEscapedUnicodeCharactersCheckTest.java:
coding/IllegalTokenCheckTest.java:
coding/MultipleStringLiteralsCheckTest.java:
coding/DefaultComesLastCheckTest.java:
coding/IllegalTypeCheckTest.java:
coding/NestedIfDepthCheckTest.java:
coding/DeclarationOrderCheckTest.java:
coding/IllegalThrowsCheckTest.java:
coding/IllegalTokenTextCheckTest.java:
coding/FinalLocalVariableCheckTest.java:
coding/IllegalInstantiationCheckTest.java:
coding/FallThroughCheckTest.java:
coding/RequireThisCheckTest.java:
coding/VariableDeclarationUsageDistanceCheckTest.java:
coding/NestedTryDepthCheckTest.java:
coding/HiddenFieldCheckTest.java:
coding/MagicNumberCheckTest.java:
coding/MatchXpathCheckTest.java:
coding/NestedForDepthCheckTest.java:
coding/ModifiedControlVariableCheckTest.java:
coding/EqualsAvoidNullCheckTest.java:
coding/ReturnCountCheckTest.java:
coding/IllegalCatchCheckTest.java:
DescendantTokenCheckTest.java:
blocks/LeftCurlyCheckTest.java:
blocks/EmptyBlockCheckTest.java:
blocks/AvoidNestedBlocksCheckTest.java:
blocks/NeedBracesCheckTest.java:
blocks/EmptyCatchBlockCheckTest.java:
blocks/RightCurlyCheckTest.java:
TrailingCommentCheckTest.java:
UncommentedMainCheckTest.java:
NewlineAtEndOfFileCheckTest.java:
header/RegexpHeaderCheckTest.java:
header/HeaderCheckTest.java:
imports/ImportControlCheckTest.java:
imports/AvoidStaticImportCheckTest.java:
imports/UnusedImportsCheckTest.java:
imports/AvoidStarImportCheckTest.java:
imports/IllegalImportCheckTest.java:
imports/CustomImportOrderCheckTest.java:
imports/ImportOrderCheckTest.java:
ArrayTypeStyleCheckTest.java:
whitespace/MethodParamPadCheckTest.java:
whitespace/TypecastParenPadCheckTest.java:
whitespace/NoLineWrapCheckTest.java:
whitespace/ParenPadCheckTest.java:
whitespace/NoWhitespaceAfterCheckTest.java:
whitespace/OperatorWrapCheckTest.java:
whitespace/WhitespaceAroundCheckTest.java:
whitespace/NoWhitespaceBeforeCheckTest.java:
whitespace/EmptyLineSeparatorCheckTest.java:
whitespace/FileTabCharacterCheckTest.java:
whitespace/EmptyForIteratorPadCheckTest.java:


javadoc/JavadocParagraphCheckTest.java: #isue exists
javadoc/AbstractJavadocCheckTest.java: # issue exists
javadoc/AtclauseOrderCheckTest.java: # issue exists
javadoc/SingleLineJavadocCheckTest.java: # issue exists
javadoc/WriteTagCheckTest.java: # issue exists
javadoc/JavadocVariableCheckTest.java: # issue exists
javadoc/JavadocMethodCheckTest.java: # issue exists
javadoc/JavadocPackageCheckTest.java:  # issue exists
javadoc/MissingJavadocTypeCheckTest.java: #issue exists
javadoc/JavadocTypeCheckTest.java: # issue exists
javadoc/JavadocStyleCheckTest.java: # issue exist
javadoc/MissingJavadocMethodCheckTest.java: # issue exists
annotation/AnnotationLocationCheckTest.java:  # issue exists
annotation/MissingOverrideCheckTest.java: # issue exists
annotation/AnnotationOnSameLineCheckTest.java: # issue exists
annotation/SuppressWarningsCheckTest.java:   # issue exists
annotation/AnnotationUseStyleCheckTest.java: # issue exists
Clone this wiki locally