Exam: Acceptance Test–Driven Development based on Concordion
Illustration from "Growing Object-Oriented Software, Guided by Tests"
Exam is oriented on declarative end-to-end black\graybox application testing in a way a manual tester would do it: send request, verify response\database\message queue etc.
- Declarative glue-code free approach
- Attractive, flexible documentation thanks to Concordion
- Widly used set of testing tools under the hood: dbunit, rest-assured, xml-unit, json-unit
// Typical microservices setup (Web API + DB + MQ) testing:
testImplementation "io.github.adven27:exam-ms:6.0.0-alpha-3"//same as://testImplementation "io.github.adven27:exam-ws:6.0.0-alpha-3"//testImplementation "io.github.adven27:exam-db:6.0.0-alpha-3"//testImplementation "io.github.adven27:exam-mq:6.0.0-alpha-3"// UI testing
testImplementation "io.github.adven27:exam-ui:6.0.0-alpha-3"For detailed info, see original tutorial
specs.Specs.java
publicclassSpecsextendsAbstractSpecs {
privatestaticConfigurableApplicationContextSUT;
@OverrideprotectedExamExtensioninit() {
returnnewExamExtension(
newWsPlugin(8080),
newDbPlugin("org.postgresql.Driver", "jdbc:postgresql://localhost:5432/postgres", "postgres", "postgres"),
newMqPlugin(Map.of("kafka", newKafkaTester("PLAINTEXT://localhost:9092", "topic")))
);
}
@OverrideprotectedvoidstartSut() {
SpringApplicationapp = newSpringApplication(Main.class);
app.setAdditionalProfiles("qa");
SUT = app.run();
}
@OverrideprotectedvoidstopSut() {
SUT.stop();
}
}specs\Specs.md
# API
- [User creation]( usercreation/UserCreation.html "c:run")specs.usercreation.UserCreation.java
publicclassUserCreationextendsSpecs {
}specs\usercreation\UserCreation.html
<htmlxmlns:e="http://exam.extension.io" xmlns:cc="http://www.concordion.org/2007/concordion"><body><h1>User creation</h1><e:examplename="My dummy user creation example"><e:given>
Given users:
<e:db-settable="user" cols="name, age, id=1..10"><e:row>Andrew, 20</e:row><e:row>Bob , 30</e:row></e:db-set></e:given><e:posturl="users"><e:casedesc="When name and age was posted user should be created and id should be returned"><e:body> {"name": "Carl", "age": 40} </e:body><e:expected> {"id": "{{number}}"} </e:expected><e:check><e:db-checktable="person" cols="name, age"><e:row>Andrew, 20</e:row><e:row>Bob , 30</e:row><e:row>Carl , 40</e:row></e:db-check></e:check></e:case><e:casedesc="Age is optional"><e:body> {"name": "Don"} </e:body><e:expected> {"id": "{{number}}"} </e:expected><e:check><e:db-checktable="person" cols="name, age" where="name='Don'"><e:row>Don, {{NULL}}</e:row></e:db-check></e:check></e:case></e:post></e:example></body></html>For more info, see live spec and demo project
