The Java Gradle and Maven plugin for the test task that reports presence of asserts in a test method body.
- Prints the number of assert calls in each test method to the console
- Excludes ignored/disabled test classes and methods from linting
- Limits the lint to recursively search from a top level package (for ex. 'org.samples')
- Allows verbose output
- Optionally loads test classes from the classpath
- JUnit 4
- JUnit 5
- TestNG
- Gradle 4.9 and above
- Maven 3.5 and above
- run
gradle clean build publishfrom the root of the project. This will
- build core module
- build plugin-gradle module
- build samples module
- install core and plugin-gradle jars into your local maven repo and into
builddir under the project root
To see the plugin in action, cd .\client-gradle
and run gradle cleanTest test . You should see the summary table:
| Package | Test file name | Test method name | # asserts |
|---|---|---|---|
| sample/junit4 | AssertJunit4Style.java | withoutAsserts | 0 |
| sample/junit5 | AssertJunit5Style.java | withAsserts | 2 |
| sample/testng | TestNgStyle.java | withAsserts | 1 |
| sample/junit4 | AssertJunit4Style.java | withAsserts | 1 |
| sample/testng | TestNgStyle.java | withoutAsserts | 0 |
| sample | DummyTest.java | dummy | 0 |
| sample/junit5 | AssertJunit5Style.java | withoutAsserts | 0 |
- run
mvn clean installfrom the root of the project. This will
- build core module
- build plugin-maven module
- build samples module
- install core jar into your local maven repo
In your build.gradle
I: add the java-lint-plugin dependency to the buildscript section:
buildscript {
dependencies {
classpath 'org.lint:plugin:0.1.0-SNAPSHOT'
}
}
II: Add the plugin: apply plugin: org.lint.azzert.LintTestsPlugin
III: Configure lint:
test{
...
lintAssert{
packageName = "org.lint" //optional or scan all
verbose = true //optional, defaults to false
includeClasspathJars = true //optional, defaults to false, scan alls jars found on the classpath
}
}
IV: run gradle clean test
In your pom.xml
I: Include the plugin in the build plugins and optionally overwrite default values in the section
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>${maven-mojo-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.lint.assert</groupId>
<artifactId>lint-assert-maven-plugin</artifactId>
<version>0.1.0-SNAPSHOT</version>
<configuration>
<includeClasspathJars>false</includeClasspathJars>
<verbose>true</verbose>
<packageName>org.lint</packageName>
</configuration>
</plugin>
...
</plugins>
...
</build>
- Exclude tests that throw expected exceptions
- Display results in alphabetic order of fully qualified test class name -
org.lint.PlaceholderTest - Print the linting summary: number of PASS/FAIL and a list of assertless tests
- Support a condensed output mode when only assertless tests are being printed
- Support 3 output modes info, warn, and error:
- in warn mode, warn if linting found assertless tests
- in error mode, fail the 'test' phase if linting found assertless tests
- Allow users to specify additional test frameworks
- When running in an IntelliJ console, make package.class.method "clickable" and navigate to the method declaration
- Display a ratio of # of asserts to the size of the "method under test" and number of its conditions
- Lint for assertness in nested test classes
The Apache 2.0 License). Please see License for more information.