Java Lint Assert Samples

Pluggable linting utility for Java tests

License

License

GNU General Public License v3.0
GroupId

GroupId

com.github.jpmorganchase.lint-assert
ArtifactId

ArtifactId

samples
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Java Lint Assert Samples
Pluggable linting utility for Java tests

Download samples

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.jpmorganchase.lint-assert/samples/ -->
<dependency>
    <groupId>com.github.jpmorganchase.lint-assert</groupId>
    <artifactId>samples</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.jpmorganchase.lint-assert/samples/
implementation 'com.github.jpmorganchase.lint-assert:samples:1.0.1'
// https://jarcasting.com/artifacts/com.github.jpmorganchase.lint-assert/samples/
implementation ("com.github.jpmorganchase.lint-assert:samples:1.0.1")
'com.github.jpmorganchase.lint-assert:samples:jar:1.0.1'
<dependency org="com.github.jpmorganchase.lint-assert" name="samples" rev="1.0.1">
  <artifact name="samples" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.jpmorganchase.lint-assert', module='samples', version='1.0.1')
)
libraryDependencies += "com.github.jpmorganchase.lint-assert" % "samples" % "1.0.1"
[com.github.jpmorganchase.lint-assert/samples "1.0.1"]

Dependencies

compile (7)

Group / Artifact Type Version
org.testng : testng jar 6.9.10
junit : junit jar 4.13.1
org.junit.vintage : junit-vintage-engine jar 5.7.0
org.mockito : mockito-core jar 3.1.0
org.assertj : assertj-core jar 3.18.1
org.junit.jupiter : junit-jupiter-api jar 5.7.0
org.junit.jupiter : junit-jupiter-engine jar 5.7.0

Project Modules

There are no modules declared in this project.

Pluggable linting utility for Java tests

License Build Status

The Java Gradle and Maven plugin for the test task that reports presence of asserts in a test method body.

Features:

  1. Prints the number of assert calls in each test method to the console
  2. Excludes ignored/disabled test classes and methods from linting
  3. Exclude tests that throw expected exceptions
  4. Limits the lint to recursively search from a top level package (for ex. 'org.samples')
  5. Allows verbose output
  6. Optionally loads test classes from the classpath
  7. Optionally condenses output to print only assert-less tests

Supported Testing Frameworks:

  • JUnit 4
  • JUnit 5
  • TestNG

Supported build types:

  • Gradle 4.9 and above
  • Maven 3.5 and above

Installation:

  1. git clone https://github.com/jpmorganchase/java-lint-assert.git

Gradle:

  1. run gradle clean build publish from 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 build dir 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

Maven:

  1. run mvn clean install from 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

Use:

Gradle:

In your build.gradle

I: add the java-lint-plugin dependency to the buildscript section:

buildscript {
   dependencies {
        classpath 'org.lint:plugin:0.3.0-SNAPSHOT'
    }
}

II: Add the plugin: apply plugin: org.lint.azzert.LintTestsPlugin

III: Configure lint:

test{
   ...   
    lintAssert{
        packageName = "sample" //optional or scan all
    }
}

IV: run gradle clean test

Maven:

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>com.github.jpmorganchase.lint-assert</groupId>
                <artifactId>lint-assert-maven-plugin</artifactId>
                <version>0.3.0-SNAPSHOT</version>
                <configuration>
                    <!-- optional or scan all -->
                    <packageName>sample</packageName>
                </configuration>
                <executions>
                    <execution>
                        <phase>test</phase>
                        <goals>
                            <goal>lint-assert</goal>
                        </goals>
                    </execution>
                </executions> 
            </plugin>
            ...
        </plugins>
        ...
    </build>

II: run mvn clean test

Available configuration options:

Option Required? Default value Values Purpose
includeClasspathJars No false true, false If true, scans classpath dependencies for test classes
verbose No false true, false If true, produced a lot of output before it prints the summary table
packageName No tests package name (for ex. org.lint in Maven or "org.lint" in Gradle) A root package to start scanning for test classes. If not specified, scans all packages in a project.
printMode No ASSERTLESS_ONLY Maven: {ALL, ASSERTLESS_ONLY}, Gradle: {"ALL", "ASSERTLESS_ONLY"} Print ALL available test methods or ASSERTLESS_ONLY

Future features:

  1. Credit use of AssertJ's asserts
  2. Credit use of Mockito's verify(...)
  3. Display results in alphabetic order of fully qualified test class name - org.lint.PlaceholderTest - or order by number of asserts
  4. Print the linting summary: number of PASS/FAIL and a list of tests without verifications
  5. Support 3 output modes info, warn, and error:
    • in warn mode, warn if linting found tests without verifications
    • in error mode, fail the 'test' phase if linting found tests without verifications
  6. Allow users to specify additional test frameworks
  7. When running in an IntelliJ console, make package.class.method "clickable" and navigate to the method declaration
  8. Display a ratio of # of asserts to the size of the "method under test" and number of its conditions
  9. Lint nested test classes
  10. Lint nested methods (testing utility methods for ex.)

License

The Apache 2.0 License). Please see License for more information.

com.github.jpmorganchase.lint-assert

J.P. Morgan Chase

Versions

Version
1.0.1
1.0.0
0.2.2
0.2.1
0.2.0
0.1.7
0.1.0