Skip to content

Sample project to demonstrate automated acceptance testing with BDD and code coverage of both Java and Javascript source code.

Notifications You must be signed in to change notification settings

noorulhaq/spring-petclinic

Repository files navigation

#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.

alt tag

Acceptance tests are written using following frameworks:

Below is the sample automated acceptance test outcome that you will find in spring-petclinic-it/target/site/serenity folder after execution of tests: alt tag

spring-petclinic (AUT)

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:

spring-petclinic-api

Exposes restful api consumed by spring-petclinic-web module.

spring-petclinic-domain

Contains the application domain till application service layer.

spring-petclinic-web

Contains web layer artifacts developed in AngularJS.

spring-petclinic-common

Common project shared among multiple modules.

spring-petclinic-it

Contains automated acceptance tests.

Execution Steps

  1. 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.

About

Sample project to demonstrate automated acceptance testing with BDD and code coverage of both Java and Javascript source code.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published