#Automated Acceptance Testing with Code Coverage
The purpose of this project is to demonstrate how coverage against BDD based acceptance tests can be achieved for both java and javascript at the same time. Code coverage is achieved using following libraries:
- JSCover (File system based instrumentation for javascript code coverage).
- Jacoco (On-the-fly code instrumentation for java code coverage).
After following execution steps you should be able to see covergae results in sonar as shown below.
Acceptance tests are written using following frameworks:
- Cucumber (BDD)
- Selenium Webdrive (Integration Testing)
- Serenity (BDD and Integration Testing orchestrator)
Below is the sample automated acceptance test outcome that you will find in spring-petclinic-it/target/site/serenity folder after execution of tests:
Application under test is taken from a sample spring-petclinic application. I have just decomposed the application into multiple modules to create a multimodule maven project.
Decomposed modules are described below:
Exposes restful api consumed by spring-petclinic-web module.
Contains the application domain till application service layer.
Contains web layer artifacts developed in AngularJS.
Common project shared among multiple modules.
Contains automated acceptance tests.
- Run mvn clean install at project root level.
- Launch api project using mvn cargo:run -P cargo-tomcat command inside spring-petclinic-api module.
- Launch api project using mvn cargo:run -P cargo-tomcat command inside spring-petclinic-web module.
- Access web application from any proxy server (Apache, Nginx) to avoid CORS issues. Refer to sample [configuration file] (https://github.com/noorulhaq/spring-petclinic/blob/master/assets/httpd.conf) provided in assests folder for apache web server.
- Execute acceptance tests using mvn verify -e -P it-tests,Dev command from spring-petclinic-it module with following JVM arguments:
-Dselenium.driver=org.openqa.selenium.chrome.ChromeDriver
-Dwebdriver.chrome.driver=/path/to/chromedriver. You can download chrome driver from here
-Dserver.jmx.url=rmi://localhost:9999/jmxrmi
-Dwebdriver.base.url=http://localhost:7272
Here webdriver.base.url is the url where your webserver serves the petclinic application. - Run mvn verify -e -P collect-it-data at project root level to collect the code coverage stats with following JVM arguments:
-Dserver.jmx.url=rmi://localhost:9999/jmxrmi - Finally, run mvn sonar:sonar -pl !spring-petclinic-it,!spring-petclinic-common -Dsonar.host.url=http://docker.me:9001 command at project root level to submit the stats to sonarQube. Change Dsonar.host.url value to your sonarQube location.
##Note## If you are not interested in code coverage then you can skip last two steps.