-
Notifications
You must be signed in to change notification settings - Fork 0
Version2 in English
In this document, I explain about version2 of assertjGen-gradle-plugin.
If you want examine about version1, please read the Version1 document.
Version1 wraps the CLI api of the AssertJ Assertions Generator simply.
Version1 function was limited because the CLI api does not support full functions of AssertJ Assertion Generator.
On the other hand Version2 wraps the AssertJ Assertions Generator Maven Plugin completely.
Therefore Version2 can supply same functions as Maven Plugin.
See Gradle - Plugin: com.github.opengl-BOBO.assertjGen2.
This plugin add assertjGen
task.
This task generates Assertion Classes by AssertJ Assertions Generator.
build.gradle
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.github.opengl-8080:assertjGen-gradle-plugin:2.0.0"
}
}
apply plugin: "com.github.opengl-BOBO.assertjGen2"
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:3.5.2'
}
assertjGen {
packages = ['foo.bar']
}
Apply plugin, and configure each options by assertjGen
block.
Version2 has same options as Maven Plugin.
Therefore you can configure same as Maven Plugin basically.
The most difference to Maven Plugin, some notations are based on Gradle (Groovy) notation.
assertjGen {
packages = ['foo.bar', 'fizz.buzz']
classes = ['foo.bar.SomeClass', 'fizz.buzz.AnyClass']
hierarchical = true
generateAssertionsForAllFields = false
entryPointClassPackage = 'foo.assertions'
includes = [/foo\.bar\.Fizz.*/]
excludes = [/foo\.bar\.Buzz.*/]
targetDir = "${buildDir}/foo/bar"
cleanTargetDir = true
generateAssertionsInPackage = 'foo.my.assertions'
generateAssertions = true
generateBddAssertions = true
generateSoftAssertions = true
generateJUnitSoftAssertions = true
generatedSourcesScope = 'test'
quiet = false
writeReportInFile = "${buildDir}/report.txt"
skip = false
templates {
templatesDirectory = 'src/test/resources/tesmplates/'
objectAssertion = 'custom_object_assertion.txt'
}
}
Please read the original document for more details.
Gradle Plugin add some options.
assertjGen {
packages = ['sample']
configurations = ['customconfiguration']
}
configurations {
customconfiguration {
canBeResolved = true
}
}
dependencies {
customconfiguration "org.antlr:antlr4-runtime:4.7"
}
You can add configurations if you want add custom configurations other than compile
and testCompile
.
You must set canBeResolved = true
to custom configuration.
sourceSets {
api.java.srcDir { "src/api/java" }
}
assertjGen {
packages = ['sample']
sourceSets = ['api']
}
tasks.assertjGen.dependsOn('compileApiJava')
You can add sourceSets if you want add custom sourceSet other than main
and test
.
The custom sourceSet must be compiled before assertjGen
task is executed.
Therefore you must configure that assertjGen
depends on a compile task of custom sourceSet.
IDE (like InteliJ IDEA) needs to recognize generated classes.
Normally assertjGen
task adds generated classes into classpath only at runtime.
Therefore IDE can not see generated classes.
You need to add an output directory to test
sourceSet.
assertjGen {
packages = ["sample"]
}
sourceSets {
test {
java {
srcDirs assertjGen.resolveTargetDir(project)
}
}
}
assertjGen.resolveTargetDir(project)
returns an output directory.
- v2.0.0 (2017-12-10)
- First Release
- Rebuilt to wrap the maven plugin completely.