diff --git a/README.md b/README.md index 1022f38..e010679 100644 --- a/README.md +++ b/README.md @@ -63,405 +63,24 @@ usage example. Java code, tests and documentation become tightly coupled by putt ## WHAT? -[jdoc-spock](#jdoc-spock) jupiter engine library runs [spockframework](https://spockframework.org/) test specifications written in javadocs. +| Component | Type | Description | +| --------- | ---- | ----------- | +| [jdoc-spock](jdoc-spock/README.md) | junit engine library | Runs [spockframework](https://spockframework.org/) test specifications written in javadocs. | +| [jdoc-spock-gradle-plugin](jdoc-spock-gradle-plugin/README.md) | gradle plugin | [Automates](https://plugins.gradle.org/plugin/io.github.boolivar.jdoctest.jdoc-spock) spockframework specs generation and testing. | +| [jdoc-cucumber](jdoc-cucumber/README.md) | junit engine library | Runs [gherkin](https://cucumber.io/docs/gherkin/reference/) features written in javadocs. | +| [jdoc-cucumber-gradle-plugin](jdoc-cucumber-gradle-plugin/README.md) | gradle plugin | [Automates](https://plugins.gradle.org/plugin/org.bool.jdoctest.jdoc-cucumber) cucumber feature generation and testing. | -[jdoc-spock-gradle-plugin](#jdoc-spock-gradle-plugin) gradle [plugin](https://plugins.gradle.org/plugin/io.github.boolivar.jdoctest.jdoc-spock) automates spockframework specs generation and testing. - -[jdoc-cucumber](#jdoc-cucumber) jupiter engine library runs [gherkin](https://cucumber.io/docs/gherkin/reference/) features written in javadocs. - -[jdoc-cucumber-gradle-plugin](#jdoc-cucumber-gradle-plugin) gradle [plugin](https://plugins.gradle.org/plugin/org.bool.jdoctest.jdoc-cucumber) automates cucumber feature generation and testing. - -:warning: **Library tests itself using itself executing own `jdoc-spock` tests written in javadocs.** +:warning: **Library tests itself using itself executing own `jdoc-spock` tests written in javadocs.** ## WHAT??? Yes, see `jdoc-spock` and `jdoc-cucumber` [test](https://github.com/boolivar/jdoc-test/blob/master/jdoc-spock-commons/src/main/java/org/bool/jdoc/spock/ResourceContainer.java) [examples](https://github.com/boolivar/jdoc-test/blob/master/jdoc-cucumber/src/main/java/org/bool/jdoc/cucumber/ConfigParams.java) in [source](https://github.com/boolivar/jdoc-test/blob/master/jdoc-core/src/main/java/org/bool/jdoc/core/JavaFileParser.java) [code](https://github.com/boolivar/jdoc-test/blob/master/jdoc-spock-commons/src/main/java/org/bool/jdoc/spock/ClassIntrospector.java). -## How? - -### jdoc-spock - - -```xml - - io.github.boolivar.jdoctest - jdoc-spock - 0.12.0 - test - -``` - - ---- - -1. Write `jdoc-spock` tests. - -`jdoc-spock` contains junit platform engine to run tests. It considers text in javadoc or block comment between `` `` tags as spock specification code. -Additional non-mandatory `
` tag keeps code formatting for javadoc presentation:
-```java
-/**
- * 

- * def "Calling delegate bar method"() {
- *   when:
- *     $target.foo()
- *   then:
- *     1 * delegate.bar()
- * }
- * 
- */ -public void foo() { - delegate.bar(); -} -``` - -2. Add `jdoc-spock` dependency. - -`build.gradle` example: - -```gradle -repositories { - mavenCentral() -} - -dependencies { - testRuntimeOnly "io.github.boolivar.jdoctest:jdoc-spock:0.12.0" -} -``` - - -> [!IMPORTANT] -> `jdoc-spock` versions before `0.9.0` available only on [jitpack](https://jitpack.io/#boolivar/jdoc-test). -> -> ```gradle -> repositories { -> maven { url "https://jitpack.io" } -> } -> -> dependencies { -> testRuntimeOnly "io.github.boolivar.jdoctest:jdoc-spock:0.8.1" -> } -> ``` - -3. Compile java code with parameter names using `javac` `-parameters` argument. - -`build.gradle` example: -```gradle -compileJava { - options.compilerArgs << "-parameters" -} -``` - -`jdoc-spock` uses constructor argument names to generate fields in specification initialized with mocks. -`$target` field of spock specification is initialized with instance of class under test (instance of primary class in java file where jdoc-spock specification is located). -`jdoc-spock` searches for biggest constructor with mockable (non-final class) arguments and creates mock for each constructor argument. Mocks stored in spec fields using corresponding names. - -As an example for java class: - -```java -public class Foo { - - private final Bar delegate; - - public Foo(Bar delegate) { - this.delegate = delegate; - } -} -``` - -generated spock fields will be: -```groovy -def delegate = Mock(Bar) -def $target = new Foo(delegate) -``` - -4. Set up paths to java sources using test suite `@SelectDirectories` or `@SelectFile`: - -```java -import org.junit.platform.suite.api.IncludeEngines; -import org.junit.platform.suite.api.SelectDirectories; -import org.junit.platform.suite.api.Suite; - -@Suite -@IncludeEngines("jdoc-spock") -@SelectDirectories("src/main/java") -public class JdocSpockTestSuite { -} -``` - -jdoc-spock supports platform engine `DiscoverySelector` and `FileSelector`. - -Optionally comma-separated paths to java sources can be provided using either `jdoc.spock.test-dirs` or `jdoc.spock.test-files` junit platform [Configuration Parameters](https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params). - -`build.gradle` example: -```gradle -test { - useJUnitPlatform() - systemProperties = ["jdoc.spock.test-dirs" : sourceSets.main.java.srcDirs.join(",")] -} -``` - -5. Run tests with `jdoc-spock` junit engine. - -`gradle` example: -```sh -gradle test -``` - -### jdoc-cucumber - - -```xml - - io.github.boolivar.jdoctest - jdoc-cucumber - 0.12.0 - test - -``` - - ---- - -1. Write jdoc gherkin feature using `` tag: - -```java -/** - *

- * Feature: foo() invokes bar()
- *   Scenario: invoke foo()
- *     When invoke foo()
- *     Then bar() invoked
- * 
- */ -public class Foo { - - private final Bar bar; - - public Foo(Bar bar) { - this.bar = bar; - } - - public void foo() { - bar.bar(); - } -} -``` - -2. Provide cucumber and jdoc-cucumber test dependencies. - -`build.gradle` example: -
-repositories {
-    mavenCentral()
-}
-
-dependencies {
-    testRuntimeOnly "io.github.boolivar.jdoctest:jdoc-cucumber:0.12.0"
-    testImplementation "io.cucumber:cucumber-java:7.17.0"
-}
-
- -> [!IMPORTANT] -> `jdoc-cucumber` versions before `0.9.0` available only on [jitpack](https://jitpack.io/#boolivar/jdoc-test). -> -> `build.gradle` example: -> ```gradle -> repositories { -> maven { url "https://jitpack.io" } -> } -> dependencies { -> testRuntimeOnly "io.github.boolivar.jdoctest:jdoc-cucumber:0.8.1" -> testImplementation "io.cucumber:cucumber-java:7.17.0" -> } -> ``` - -3. Write cucumber step definitions. - -```java -import io.cucumber.java.en.Then; -import io.cucumber.java.en.When; - -import static org.mockito.BDDMockito.*; - -public class StepDefinitions { - - private final Bar bar = mock(Bar.class); - - private final Foo foo = new Foo(bar); - - @When("invoke foo()") - public void invokeFoo() { - foo.foo(); - } - - @Then("bar() invoked") - public void verifyBarInvoked() { - then(bar).should().bar(); - } -} -``` - -4. Set up paths to java sources using test suite `@SelectDirectories` or `@SelectFile` and step definitions package -using `io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME` configuration parameter: - -```java -import org.junit.platform.suite.api.ConfigurationParameter; -import org.junit.platform.suite.api.IncludeEngines; -import org.junit.platform.suite.api.SelectDirectories; -import org.junit.platform.suite.api.Suite; - -import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME; - -@Suite -@IncludeEngines("jdoc-cucumber") -@SelectDirectories("src/main/java") -@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "step.definitions.package") -public class JdocCucumberTestSuite { -} -``` - -5. Run tests with `jdoc-cucumber` junit engine. - -`gradle` example: -```sh -gradle test -``` - -### jdoc-cucumber-gradle-plugin - ---- - -Gradle plugin available on [gradle plugin portal](https://plugins.gradle.org/plugin/io.github.boolivar.jdoctest.jdoc-cucumber) that automates cucumber feature generation and cucumber testing tasks. - -#### Minimal configuration: -`build.gradle`: - -```gradle -plugins { - id "java" - id "io.github.boolivar.jdoctest.jdoc-cucumber" version "0.12.0" -} - -repositories { - mavenCentral() -} - -check.dependsOn jdocCucumberTest -``` - - -```sh -gradle check -``` - -#### jdocCucumber extension -`build.gradle` example: -```gradle -jdocCucumber { - gluePackages = ["org.bool.cucumber.stepdefs"] - cucumberVersion = "7.18.1" - sources = sourceSets.custom.java -} -``` - -| Extension property | Type | Default value | Description | -| ------------------ | ---- | ------------- | ----------- | -| `outputDir` | `Directory` | project.layout.buildDirectory.dir("generated/sources/jdoc-cucumber") | Path to store generated features | -| `langTag` | `String` | "gherkin" | `lang` tag to parse. Only `` javadoc blocks will be parsed and written as features | -| `sources` | `FileCollection` | sourceSets.main.java.sourceDirectories | source directories to search java files with jdoc-cucumber comments | -| `cucumberVersion` | `String` | "7.17.0" | `io.cucumber:cucumber-java` dependency version to register in `testImplementation` configuration | -| `gluePackages` | `List` | | List of packages with cucumber glue code | - -#### Tasks -When `java` plugin is applied to a project, `jdoc-cucumber` plugin registers `io.cucumber:cucumber-java` dependency in `testImplementation` configuration and creates 2 tasks: -- **generateCucumberFeatures** - `JdocCucumberTask` - Generates cucumber features from javadocs and stores them in `jdocCucumber.outputDir` path. -- **jdocCucumberTest** - `JavaExec` - _Depends on:_ all tasks with type `JdocCucumberTask`. Runs cucumber tests using cucumber CLI Runner. - -> [!NOTE] -> By default `jdocCucumberTest` task is **not a dependency** for `check` task. To include `jdocCucumberTest` in build this should be configured manually. -> -> `build.gradle` example: -> ```gradle -> check.dependsOn jdocCucumberTest -> ``` - -### jdoc-spock-gradle-plugin - ---- - -Gradle plugin available on [gradle plugin portal](https://plugins.gradle.org/plugin/io.github.boolivar.jdoctest.jdoc-spock) that automates spockframework specs generation and testing tasks. - -#### Configuration example -`build.gradle`: - -```gradle -plugins { - id "java" - id "io.github.boolivar.jdoctest.jdoc-spock" version "0.12.0" -} - -repositories { - mavenCentral() -} - -jdocSpockTest { - testLogging { - events "passed", "skipped", "failed" - } -} - -check.dependsOn jdocSpockTest -``` - - -```sh -gradle check -``` - -#### Reacting to the java plugin -When `java` plugin is applied to a project, `jdoc-spock` plugin: -- applies `groovy` plugin -- creates source set `jdocSpock` with groovy sources configured to outputDir property of extension -- registers `org.spockframework:spock-core` as implementation dependency for `jdocSpock` source set -- registers `net.bytebuddy:byte-buddy` and `org.objenesis:objenesis` as runtimeOnly dependencies for `jdocSpock` source set -- creates `generateSpockSpecs` task -- creates `jdocSpockTest` task -- configures `compileJdocSpockGroovy` task to depend on `generateSpockSpecs` task - -#### jdocSpock extension -`build.gradle` example: -```gradle -jdocSpock { - outputDir = project.layout.buildDirectory.dir("spock-specs") - spockVersion = "2.3-groovy-4.0" - byteBuddyVersion = null - objenesisVersion = null -} -``` - -| Extension property | Type | Default value | Description | -| ------------------ | ---- | ------------- | ----------- | -| `outputDir` | `Directory` | project.layout.buildDirectory.dir("generated/sources/jdoc-spock") | Path to store generated groovy specs | -| `langTag` | `String` | "spock" | `lang` tag to parse. Only `` javadoc blocks will be parsed and included in spec generation | -| `sources` | `FileCollection` | sourceSets.main.java.sourceDirectories | source directories to search java files with jdoc-spock comments | -| `classPath` | `FileCollection` | sourceSets.jdocSpock.compileClasspath | Classpath for mockable constructor search during spec generation. | -| `spockVersion` | `String` | "2.3-groovy-4.0" | `org.spockframework:spock-core` dependency version to register in `jdocSpockImplementation` configuration | -| `byteBuddyVersion` | `String` | "1.14.15" | `net.bytebuddy:byte-buddy` dependency version to register in `jdocSpockRuntimeOnly` configuration, `null` value will exclude dependency. | -| `objenesisVersion` | `String` | "3.3" | `org.objenesis:objenesis` dependency version to register in `jdocSpockRuntimeOnly` configuration, `null` value will exclude dependency. | +## HOW? -#### Tasks -- **generateSpockSpecs** - `JdocSpockTask` - _Depends on:_ `compileJava`. Generates spockframework test specs from javadocs and stores them in `jdocSpock.outputDir` path. -- **jdocSpockTest** - `Test` -Runs spockframework tests using junit platform . +See the component READMEs for detailed usage: -> [!NOTE] -> By default `jdocSpockTest` task is **not a dependency** for `check` task. To include `jdocSpockTest` in build this should be configured manually. -> -> `build.gradle` example: -> -> ```gradle -> check.dependsOn jdocSpockTest -> ``` +- **[jdoc-spock](jdoc-spock/README.md)** — write and run Spock specs from javadocs using JUnit engine +- **[jdoc-cucumber](jdoc-cucumber/README.md)** — write and run Gherkin features from javadocs using JUnit engine +- **[jdoc-spock-gradle-plugin](jdoc-spock-gradle-plugin/README.md)** — automate Spock spec generation and testing via Gradle +- **[jdoc-cucumber-gradle-plugin](jdoc-cucumber-gradle-plugin/README.md)** — automate Cucumber feature generation and testing via Gradle \ No newline at end of file diff --git a/jdoc-cucumber-gradle-plugin/README.md b/jdoc-cucumber-gradle-plugin/README.md new file mode 100644 index 0000000..c21546a --- /dev/null +++ b/jdoc-cucumber-gradle-plugin/README.md @@ -0,0 +1,57 @@ +# jdoc-cucumber-gradle-plugin + +> Part of [jdoc-test](../README.md). Gradle plugin available on [gradle plugin portal](https://plugins.gradle.org/plugin/io.github.boolivar.jdoctest.jdoc-cucumber) that automates cucumber feature generation and cucumber testing tasks. + +## Minimal configuration: +`build.gradle`: + +```gradle +plugins { + id "java" + id "io.github.boolivar.jdoctest.jdoc-cucumber" version "0.12.0" +} + +repositories { + mavenCentral() +} + +check.dependsOn jdocCucumberTest +``` + + +```sh +gradle check +``` + +## jdocCucumber extension +`build.gradle` example: +```gradle +jdocCucumber { + gluePackages = ["org.bool.cucumber.stepdefs"] + cucumberVersion = "7.18.1" + sources = sourceSets.custom.java +} +``` + +| Extension property | Type | Default value | Description | +| ------------------ | ---- | ------------- | ----------- | +| `outputDir` | `Directory` | project.layout.buildDirectory.dir("generated/sources/jdoc-cucumber") | Path to store generated features | +| `langTag` | `String` | "gherkin" | `lang` tag to parse. Only `` javadoc blocks will be parsed and written as features | +| `sources` | `FileCollection` | sourceSets.main.java.sourceDirectories | source directories to search java files with jdoc-cucumber comments | +| `cucumberVersion` | `String` | "7.17.0" | `io.cucumber:cucumber-java` dependency version to register in `testImplementation` configuration | +| `gluePackages` | `List` | | List of packages with cucumber glue code | + +## Tasks +When `java` plugin is applied to a project, `jdoc-cucumber` plugin registers `io.cucumber:cucumber-java` dependency in `testImplementation` configuration and creates 2 tasks: +- **generateCucumberFeatures** - `JdocCucumberTask` + Generates cucumber features from javadocs and stores them in `jdocCucumber.outputDir` path. +- **jdocCucumberTest** - `JavaExec` + _Depends on:_ all tasks with type `JdocCucumberTask`. Runs cucumber tests using cucumber CLI Runner. + +> [!NOTE] +> By default `jdocCucumberTest` task is **not a dependency** for `check` task. To include `jdocCucumberTest` in build this should be configured manually. +> +> `build.gradle` example: +> ```gradle +> check.dependsOn jdocCucumberTest +> ``` diff --git a/jdoc-cucumber/README.md b/jdoc-cucumber/README.md new file mode 100644 index 0000000..c62aaca --- /dev/null +++ b/jdoc-cucumber/README.md @@ -0,0 +1,121 @@ +# jdoc-cucumber + +> Part of [jdoc-test](../README.md). Runs [gherkin](https://cucumber.io/docs/gherkin/reference/) features written in javadocs. + + +```xml + + io.github.boolivar.jdoctest + jdoc-cucumber + 0.12.0 + test + +``` + + +--- + +1. Write jdoc gherkin feature using `` tag: + +```java +/** + *

+ * Feature: foo() invokes bar()
+ *   Scenario: invoke foo()
+ *     When invoke foo()
+ *     Then bar() invoked
+ * 
+ */ +public class Foo { + + private final Bar bar; + + public Foo(Bar bar) { + this.bar = bar; + } + + public void foo() { + bar.bar(); + } +} +``` + +2. Provide cucumber and jdoc-cucumber test dependencies. + +`build.gradle` example: +
+repositories {
+    mavenCentral()
+}
+
+dependencies {
+    testRuntimeOnly "io.github.boolivar.jdoctest:jdoc-cucumber:0.12.0"
+    testImplementation "io.cucumber:cucumber-java:7.17.0"
+}
+
+ +> [!IMPORTANT] +> `jdoc-cucumber` versions before `0.9.0` available only on [jitpack](https://jitpack.io/#boolivar/jdoc-test). +> +> `build.gradle` example: +> ```gradle +> repositories { +> maven { url "https://jitpack.io" } +> } +> dependencies { +> testRuntimeOnly "io.github.boolivar.jdoctest:jdoc-cucumber:0.8.1" +> testImplementation "io.cucumber:cucumber-java:7.17.0" +> } +> ``` + +3. Write cucumber step definitions. + +```java +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +import static org.mockito.BDDMockito.*; + +public class StepDefinitions { + + private final Bar bar = mock(Bar.class); + + private final Foo foo = new Foo(bar); + + @When("invoke foo()") + public void invokeFoo() { + foo.foo(); + } + + @Then("bar() invoked") + public void verifyBarInvoked() { + then(bar).should().bar(); + } +} +``` + +4. Set up paths to java sources using test suite `@SelectDirectories` or `@SelectFile` and step definitions package +using `io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME` configuration parameter: + +```java +import org.junit.platform.suite.api.ConfigurationParameter; +import org.junit.platform.suite.api.IncludeEngines; +import org.junit.platform.suite.api.SelectDirectories; +import org.junit.platform.suite.api.Suite; + +import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME; + +@Suite +@IncludeEngines("jdoc-cucumber") +@SelectDirectories("src/main/java") +@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "step.definitions.package") +public class JdocCucumberTestSuite { +} +``` + +5. Run tests with `jdoc-cucumber` junit engine. + +`gradle` example: +```sh +gradle test +``` diff --git a/jdoc-spock-gradle-plugin/README.md b/jdoc-spock-gradle-plugin/README.md new file mode 100644 index 0000000..9bb7ae2 --- /dev/null +++ b/jdoc-spock-gradle-plugin/README.md @@ -0,0 +1,76 @@ +# jdoc-spock-gradle-plugin + +> Part of [jdoc-test](../README.md). Gradle plugin available on [gradle plugin portal](https://plugins.gradle.org/plugin/io.github.boolivar.jdoctest.jdoc-spock) that automates spockframework specs generation and testing tasks. + +## Configuration example +`build.gradle`: + +```gradle +plugins { + id "java" + id "io.github.boolivar.jdoctest.jdoc-spock" version "0.12.0" +} + +repositories { + mavenCentral() +} + +jdocSpockTest { + testLogging { + events "passed", "skipped", "failed" + } +} + +check.dependsOn jdocSpockTest +``` + + +```sh +gradle check +``` + +## Reacting to the java plugin +When `java` plugin is applied to a project, `jdoc-spock` plugin: +- applies `groovy` plugin +- creates source set `jdocSpock` with groovy sources configured to outputDir property of extension +- registers `org.spockframework:spock-core` as implementation dependency for `jdocSpock` source set +- registers `net.bytebuddy:byte-buddy` and `org.objenesis:objenesis` as runtimeOnly dependencies for `jdocSpock` source set +- creates `generateSpockSpecs` task +- creates `jdocSpockTest` task +- configures `compileJdocSpockGroovy` task to depend on `generateSpockSpecs` task + +## jdocSpock extension +`build.gradle` example: +```gradle +jdocSpock { + outputDir = project.layout.buildDirectory.dir("spock-specs") + spockVersion = "2.3-groovy-4.0" + byteBuddyVersion = null + objenesisVersion = null +} +``` + +| Extension property | Type | Default value | Description | +| ------------------ | ---- | ------------- | ----------- | +| `outputDir` | `Directory` | project.layout.buildDirectory.dir("generated/sources/jdoc-spock") | Path to store generated groovy specs | +| `langTag` | `String` | "spock" | `lang` tag to parse. Only `` javadoc blocks will be parsed and included in spec generation | +| `sources` | `FileCollection` | sourceSets.main.java.sourceDirectories | source directories to search java files with jdoc-spock comments | +| `classPath` | `FileCollection` | sourceSets.jdocSpock.compileClasspath | Classpath for mockable constructor search during spec generation. | +| `spockVersion` | `String` | "2.3-groovy-4.0" | `org.spockframework:spock-core` dependency version to register in `jdocSpockImplementation` configuration | +| `byteBuddyVersion` | `String` | "1.14.15" | `net.bytebuddy:byte-buddy` dependency version to register in `jdocSpockRuntimeOnly` configuration, `null` value will exclude dependency. | +| `objenesisVersion` | `String` | "3.3" | `org.objenesis:objenesis` dependency version to register in `jdocSpockRuntimeOnly` configuration, `null` value will exclude dependency. | + +## Tasks +- **generateSpockSpecs** - `JdocSpockTask` + _Depends on:_ `compileJava`. Generates spockframework test specs from javadocs and stores them in `jdocSpock.outputDir` path. +- **jdocSpockTest** - `Test` + Runs spockframework tests using junit platform . + +> [!NOTE] +> By default `jdocSpockTest` task is **not a dependency** for `check` task. To include `jdocSpockTest` in build this should be configured manually. +> +> `build.gradle` example: +> +> ```gradle +> check.dependsOn jdocSpockTest +> ``` diff --git a/jdoc-spock/README.md b/jdoc-spock/README.md new file mode 100644 index 0000000..6c84320 --- /dev/null +++ b/jdoc-spock/README.md @@ -0,0 +1,130 @@ +# jdoc-spock + +> Part of [jdoc-test](../README.md). Runs [spockframework](https://spockframework.org/) test specifications written in javadocs. + +`jdoc-spock` contains a junit platform engine to run tests. It considers text in javadoc or block comment between `` `` tags as spock specification code. +Additional non-mandatory `
` tag keeps code formatting for javadoc presentation:
+
+
+```xml
+
+    io.github.boolivar.jdoctest
+    jdoc-spock
+    0.12.0
+    test
+
+```
+
+
+---
+
+1. Write `jdoc-spock` tests.
+
+```java
+/**
+ * 

+ * def "Calling delegate bar method"() {
+ *   when:
+ *     $target.foo()
+ *   then:
+ *     1 * delegate.bar()
+ * }
+ * 
+ */ +public void foo() { + delegate.bar(); +} +``` + +2. Add `jdoc-spock` dependency. + +`build.gradle` example: + +```gradle +repositories { + mavenCentral() +} + +dependencies { + testRuntimeOnly "io.github.boolivar.jdoctest:jdoc-spock:0.12.0" +} +``` + + +> [!IMPORTANT] +> `jdoc-spock` versions before `0.9.0` available only on [jitpack](https://jitpack.io/#boolivar/jdoc-test). +> +> ```gradle +> repositories { +> maven { url "https://jitpack.io" } +> } +> +> dependencies { +> testRuntimeOnly "io.github.boolivar.jdoctest:jdoc-spock:0.8.1" +> } +> ``` + +3. Compile java code with parameter names using `javac` `-parameters` argument. + +`build.gradle` example: +```gradle +compileJava { + options.compilerArgs << "-parameters" +} +``` + +`jdoc-spock` uses constructor argument names to generate fields in specification initialized with mocks. +`$target` field of spock specification is initialized with instance of class under test (instance of primary class in java file where jdoc-spock specification is located). +`jdoc-spock` searches for biggest constructor with mockable (non-final class) arguments and creates mock for each constructor argument. Mocks stored in spec fields using corresponding names. + +As an example for java class: + +```java +public class Foo { + + private final Bar delegate; + + public Foo(Bar delegate) { + this.delegate = delegate; + } +} +``` + +generated spock fields will be: +```groovy +def delegate = Mock(Bar) +def $target = new Foo(delegate) +``` + +4. Set up paths to java sources using test suite `@SelectDirectories` or `@SelectFile`: + +```java +import org.junit.platform.suite.api.IncludeEngines; +import org.junit.platform.suite.api.SelectDirectories; +import org.junit.platform.suite.api.Suite; + +@Suite +@IncludeEngines("jdoc-spock") +@SelectDirectories("src/main/java") +public class JdocSpockTestSuite { +} +``` + +jdoc-spock supports platform engine `DiscoverySelector` and `FileSelector`. + +Optionally comma-separated paths to java sources can be provided using either `jdoc.spock.test-dirs` or `jdoc.spock.test-files` junit platform [Configuration Parameters](https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params). + +`build.gradle` example: +```gradle +test { + useJUnitPlatform() + systemProperties = ["jdoc.spock.test-dirs" : sourceSets.main.java.srcDirs.join(",")] +} +``` + +5. Run tests with `jdoc-spock` junit engine. + +`gradle` example: +```sh +gradle test +``` diff --git a/release-please-config.json b/release-please-config.json index 50229ba..4d467e7 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -5,7 +5,11 @@ "packages": { ".": { "extra-files": [ - "README.md" + "README.md", + "jdoc-spock/README.md", + "jdoc-cucumber/README.md", + "jdoc-spock-gradle-plugin/README.md", + "jdoc-cucumber-gradle-plugin/README.md" ] } }