The plugin for Java Gradle test
task that reports presence of assert
s in a test method body.
- Prints the number of assert calls in each test method to the console
- Excludes test methods annotated with @Ignore (JUnit4) or @Disabled (JUnit5) from linting
- Limits the lint to recursively search from a top level package (for ex. 'com.jpmorgan')
- Allows verbose output
- JUnit 4
- JUnit 5
- Gradle 4.9 and above
- git clone https://github.com/jpmorganchase/java-lint-assert.git
- run
gradle clean build publish
from the root of the project. This will
- build core module
- build plugin module
- install core and plugin jars into your local maven repo and into
build
dir under the project root
To see the plugin in action, cd .\client
and run gradle cleanTest test -i
. You should see the summary table:
Package | Test file name | Test method name | # asserts |
---|---|---|---|
org/lint | PlaceholderTest.java | dummy | 0 |
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
}
}
IV: run your tests with -i
on: gradle test -i
- Exclude test classes annotated with @Ignore (JUnit4) and @Disabled (JUnit5) from linting
- Exclude tests annotated with @Expected (JUnit 4) and Assertions.assertThrows (JUnit 5) exception from linting
- 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.