|
|
|
|
@@ -11,7 +11,7 @@ Just to make long story short - AccuREST is a tool that enables Consumer Driven
|
|
|
|
|
|
|
|
|
|
AccuREST moves TDD to the level of software architecture.
|
|
|
|
|
|
|
|
|
|
= Why?
|
|
|
|
|
== Why?
|
|
|
|
|
|
|
|
|
|
The main purposes of AccuREST are:
|
|
|
|
|
|
|
|
|
|
@@ -22,15 +22,13 @@ The main purposes of AccuREST are:
|
|
|
|
|
|
|
|
|
|
= 2. Using in your project
|
|
|
|
|
|
|
|
|
|
== Prerequisites
|
|
|
|
|
== 2.1. Gradle Project
|
|
|
|
|
|
|
|
|
|
= 2.1. Gradle Project
|
|
|
|
|
|
|
|
|
|
== Prerequisites
|
|
|
|
|
=== Prerequisites
|
|
|
|
|
|
|
|
|
|
In order to use Accurest with Wiremock you have to use gradle or maven plugin.
|
|
|
|
|
|
|
|
|
|
== Add gradle plugin
|
|
|
|
|
==== Add gradle plugin
|
|
|
|
|
|
|
|
|
|
[source,groovy,indent=0]
|
|
|
|
|
----
|
|
|
|
|
@@ -53,7 +51,7 @@ dependencies {
|
|
|
|
|
}
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
== Add maven plugin
|
|
|
|
|
==== Add maven plugin
|
|
|
|
|
|
|
|
|
|
[source,xml,indent=0]
|
|
|
|
|
----
|
|
|
|
|
@@ -75,7 +73,7 @@ dependencies {
|
|
|
|
|
|
|
|
|
|
Read more: https://github.com/Codearte/accurest-maven-plugin[accurest-maven-plugin]
|
|
|
|
|
|
|
|
|
|
== Add stubs
|
|
|
|
|
==== Add stubs
|
|
|
|
|
|
|
|
|
|
By default Accurest is looking for stubs in src/test/resources/stubs directory.
|
|
|
|
|
Directory containing stub definitions is treated as a class name, and each stub definition is treated as a single test.
|
|
|
|
|
@@ -89,11 +87,11 @@ Accurest will create test class `defaultBasePackage.MyService` with two methods
|
|
|
|
|
- shouldCreateUser()
|
|
|
|
|
- shouldReturnUser()
|
|
|
|
|
|
|
|
|
|
== Run plugin
|
|
|
|
|
=== Run plugin
|
|
|
|
|
|
|
|
|
|
Plugin registers itself to be invoked before `compileTestGroovy` task. You have nothing to do as long as you want it to be part of your build process. If you just want to generate tests please invoke `generateAccurest` task.
|
|
|
|
|
|
|
|
|
|
== Configure plugin
|
|
|
|
|
=== Configure plugin
|
|
|
|
|
|
|
|
|
|
To change default configuration just add `accurest` snippet to your Gradle config
|
|
|
|
|
|
|
|
|
|
@@ -106,7 +104,7 @@ accurest {
|
|
|
|
|
}
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
=== Configuration options
|
|
|
|
|
==== Configuration options
|
|
|
|
|
|
|
|
|
|
- **testMode** - defines mode for acceptance tests. By default MockMvc which is based on Spring's MockMvc. It can also be changed to **JaxRsClient** or to **Explicit** for real HTTP calls.
|
|
|
|
|
- **imports** - array with imports that should be included in generated tests (for example ['org.myorg.Matchers']). By default empty array []
|
|
|
|
|
@@ -120,7 +118,7 @@ accurest {
|
|
|
|
|
- **stubsOutputDir** - dir where the generated Wiremock stubs from Groovy DSL should be placed
|
|
|
|
|
- **targetFramework** - the target test framework to be used; currently Spock and JUnit are supported with Spock being the default framework
|
|
|
|
|
|
|
|
|
|
== Base class for tests
|
|
|
|
|
==== Base class for tests
|
|
|
|
|
|
|
|
|
|
When using Accurest in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified.
|
|
|
|
|
|
|
|
|
|
@@ -141,12 +139,12 @@ class MvcSpec extends Specification {
|
|
|
|
|
|
|
|
|
|
In case of using `Explicit` mode, you can use base class to initialize the whole tested app similarly as in regular integration tests. In case of `JAXRSCLIENT` mode this base class should also contain `protected WebTarget webTarget` field, right now the only option to test JAX-RS API is to start a web server.
|
|
|
|
|
|
|
|
|
|
== Invoking generated tests
|
|
|
|
|
=== Invoking generated tests
|
|
|
|
|
|
|
|
|
|
To ensure that provider side is complaint with defined contracts, you need to invoke:
|
|
|
|
|
`./gradlew generateAccurest test`
|
|
|
|
|
|
|
|
|
|
== Accurest on consumer side
|
|
|
|
|
=== Accurest on consumer side
|
|
|
|
|
|
|
|
|
|
In consumer service you need to configure Accurest plugin in exactly the same way as in case of provider. You need to copy contracts stored in src/test/resources/stubs and generate Wiremock json stubs using: `./gradlew generateWireMockClientStubs` command. Note that `stubsOutputDir` option has to be set for stub generation to work.
|
|
|
|
|
|
|
|
|
|
@@ -179,9 +177,9 @@ class LoanApplicationServiceSpec extends Specification {
|
|
|
|
|
|
|
|
|
|
Underneath LoanApplication makes a call to FraudDetection service. This request is handled by Wiremock server configured using stubs generated by Accurest.
|
|
|
|
|
|
|
|
|
|
= 2.2. Using in your Maven project
|
|
|
|
|
== 2.2. Using in your Maven project
|
|
|
|
|
|
|
|
|
|
== Add maven plugin
|
|
|
|
|
=== Add maven plugin
|
|
|
|
|
|
|
|
|
|
[source,xml,indent=0]
|
|
|
|
|
----
|
|
|
|
|
@@ -202,7 +200,7 @@ Underneath LoanApplication makes a call to FraudDetection service. This request
|
|
|
|
|
|
|
|
|
|
Read more: [accurest-maven-plugin](https://github.com/Codearte/accurest-maven-plugin)
|
|
|
|
|
|
|
|
|
|
== Add stubs
|
|
|
|
|
=== Add stubs
|
|
|
|
|
|
|
|
|
|
By default Accurest is looking for stubs in `src/test/accurest` directory.
|
|
|
|
|
Directory containing stub definitions is treated as a class name, and each stub definition is treated as a single test.
|
|
|
|
|
@@ -219,11 +217,11 @@ Accurest will create test class `defaultBasePackage.MyService` with two methods
|
|
|
|
|
- `shouldCreateUser()`
|
|
|
|
|
- `shouldReturnUser()`
|
|
|
|
|
|
|
|
|
|
== Run plugin
|
|
|
|
|
=== Run plugin
|
|
|
|
|
|
|
|
|
|
Plugin goal `generateTests` is assigned to be invoked in phase `generate-test-sources`. You have nothing to do as long as you want it to be part of your build process. If you just want to generate tests please invoke `generateTests` goal.
|
|
|
|
|
|
|
|
|
|
== Configure plugin
|
|
|
|
|
=== Configure plugin
|
|
|
|
|
|
|
|
|
|
To change default configuration just add `configuration` section to plugin definition or `execution` definition.
|
|
|
|
|
|
|
|
|
|
@@ -248,7 +246,7 @@ To change default configuration just add `configuration` section to plugin defin
|
|
|
|
|
</plugin>
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
=== Configuration options
|
|
|
|
|
==== Configuration options
|
|
|
|
|
|
|
|
|
|
- **testMode** - defines mode for acceptance tests. By default `MockMvc` which is based on Spring's MockMvc. It can also be changed to `JaxRsClient` or to `Explicit` for real HTTP calls.
|
|
|
|
|
- **basePackageForTests** - specifies base package for all generated tests. By default set to `io.codearte.accurest.tests`.
|
|
|
|
|
@@ -259,7 +257,7 @@ To change default configuration just add `configuration` section to plugin defin
|
|
|
|
|
- **mappingsDir** - dir where the generated Wiremock stubs from Groovy DSL should be placed.
|
|
|
|
|
- **testFramework** - the target test framework to be used; currently Spock and JUnit are supported with Spock being the default framework
|
|
|
|
|
|
|
|
|
|
== Base class for tests
|
|
|
|
|
==== Base class for tests
|
|
|
|
|
|
|
|
|
|
When using Accurest in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified.
|
|
|
|
|
|
|
|
|
|
@@ -280,7 +278,7 @@ class MvcSpec extends Specification {
|
|
|
|
|
|
|
|
|
|
In case of using `Explicit` mode, you can use base class to initialize the whole tested app similarly as in regular integration tests. In case of `JAXRSCLIENT` mode this base class should also contain `protected WebTarget webTarget` field, right now the only option to test JAX-RS API is to start a web server.
|
|
|
|
|
|
|
|
|
|
== Invoking generated tests
|
|
|
|
|
=== Invoking generated tests
|
|
|
|
|
|
|
|
|
|
Accurest Maven Plugins generates verification code into directory `/generated-test-sources/accurest` and attach this directory to `testCompile` goal.
|
|
|
|
|
|
|
|
|
|
@@ -320,7 +318,7 @@ For Groovy Spock code use:
|
|
|
|
|
|
|
|
|
|
To ensure that provider side is complaint with defined contracts, you need to invoke `mvn generateTest test`
|
|
|
|
|
|
|
|
|
|
== Accurest on consumer side
|
|
|
|
|
=== Accurest on consumer side
|
|
|
|
|
|
|
|
|
|
In consumer service you need to configure Accurest plugin in exactly the same way as in case of provider. You need to copy contracts stored in `src/test/accurest` and generate Wiremock json stubs using: `mvn generateStubs` command. By default generated WireMock mapping is stored in directory `target/mappings`. Your project should create from this generated mappings additional artifact with classifier `stubs` for easy deploy to maven repository.
|
|
|
|
|
|
|
|
|
|
@@ -1198,10 +1196,10 @@ Some of the properties that are repetitive can be set using system properties or
|
|
|
|
|
|
|
|
|
|
= 9. Migration Guide
|
|
|
|
|
|
|
|
|
|
= Migration to 0.4.7
|
|
|
|
|
== Migration to 0.4.7
|
|
|
|
|
- in 0.4.7 we've fixed package name (coderate to codearte) so you've to do the same in your projects. This means replacing ```io.coderate.accurest.dsl.GroovyDsl``` with ```io.codearte.accurest.dsl.GroovyDsl```
|
|
|
|
|
|
|
|
|
|
= Migration to 1.0.0-RC1
|
|
|
|
|
== Migration to 1.0.0-RC1
|
|
|
|
|
- from 1.0.0 we're distinguish ignored contracts from excluded contracts:
|
|
|
|
|
- `excludedFiles` pattern tells Accurest to skip processing those files at all
|
|
|
|
|
- `ignoredFiles` pattern tells Accurest to generate contracts and tests, but tests will be marked as `@Ignore`
|
|
|
|
|
@@ -1209,4 +1207,13 @@ Some of the properties that are repetitive can be set using system properties or
|
|
|
|
|
- from 1.0.0 the `basePackageForTests` behaviour has changed
|
|
|
|
|
- prior to the change all DSL files had to be under `contractsDslDir`/`basePackageForTests`/*subpackage* resulting in `basePackageForTests`.*subpackage* test package creation
|
|
|
|
|
- now all DSL files have to be under `contractsDslDir`/*subpackage* resulting in `basePackageForTests`.*subpackage* test package creation
|
|
|
|
|
- If you don't migrate to the new approach you will have your tests under `contractsDslDir`.`contractsDslDir`.*subpackage*
|
|
|
|
|
- If you don't migrate to the new approach you will have your tests under `contractsDslDir`.`contractsDslDir`.*subpackage*
|
|
|
|
|
|
|
|
|
|
== Migration to 1.0.7
|
|
|
|
|
- from 1.0.7 we're setting JUnit as a default testing utility. You have to pass the following option to keep Spock
|
|
|
|
|
as your first choice:
|
|
|
|
|
|
|
|
|
|
[source,groovy]
|
|
|
|
|
----
|
|
|
|
|
include::../../../accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle[tags=target_framework,indent=0]
|
|
|
|
|
----
|