- Notifications
You must be signed in to change notification settings - Fork3
Spring, Cucumber, Java 17, JUnit 5, Logback and Extent Spark Reports basic test harness. Rest Assured and Selenium test examples provided
License
cmccarthyIrl/spring-cucumber-junit-parallel-test-harness
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
| Start | |Maven |Quickstart | |
|---|---|
| Run | |JUnit |JUnit Suites |Command Line |IDE Support |Java JDK |Troubleshooting | |
| Report | |Configuration |Environment Switching |Extent HTML Reports |Logging | |
| Advanced | |Before / After Hooks |JSON Transforms |Contributing | |
The Framework usesSpring Boot Test,Cucumber,Rest Assured andSelenium client implementations.
Spring<dependencies>:
<dependecies> ... <dependency> <groupId>org.springframework.amqp</groupId> <artifactId>spring-rabbit</artifactId> <version>${spring-rabbit.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> </dependency> ...</dependecies>
Cucumber & Rest Assured<dependencies>:
<dependecies> ...<!-- Cucumber dependencies--> <dependency> <artifactId>rest-assured</artifactId> <groupId>io.rest-assured</groupId> <version>${restassured.version}</version> </dependency> <dependency> <artifactId>cucumber-java</artifactId> <groupId>io.cucumber</groupId> </dependency> <dependency> <artifactId>cucumber-spring</artifactId> <groupId>io.cucumber</groupId> </dependency> <dependency> <artifactId>cucumber-junit-platform-engine</artifactId> <groupId>io.cucumber</groupId> </dependency> ...</dependecies>
Selenium<dependencies>:
<dependecies> ... <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>${selenium-version}</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-server</artifactId> <version>${selenium-version}</version> </dependency> ...</dependecies>
- Intellij IDE -
Recommended - Java JDK 17
- Apache Maven
By using theJUnit andtheCucumber JVM@Cucumber Annotation Type we can specify our CucumberOptions like so :
cucumber.execution.parallel.enabled=truecucumber.execution.parallel.config.strategy=fixedcucumber.execution.parallel.config.fixed.parallelism=5cucumber.plugin=io.qameta.allure.cucumber6jvm.AllureCucumber6Jvm,com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:,pretty,json:target/cucumber/report.json,
Right click theWeatherRunnerTest or class and selectRun
@CucumberpublicclassWeatherRunnerTest {}
Normally you will use your IDE to run a*.feature file directly or via the*Test.java class. With theTest class,we can run tests from the command-line as well.
Note that themvn test command only runs test classes that follow the*Test.java naming convention.
You can run a single test or a suite or tests like so :
mvn test -Dtest=WeatherRunnerTestmvn test -Dtest=JunitSuiteTestNote that themvn clean install command runs all test Classes that follow the*Test.java naming convention
mvn clean installTo minimize the discrepancies between IDE versions and Locales the<sourceEncoding> is set toUTF-8
<properties> ... <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> ...</properties>
The Java version to use is defined in themaven-compiler-plugin
<build> ... <pluginManagement> <plugins> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>11</source> <target>11</target> </configuration> </plugin> ... </plugins> </pluginManagement> ...</build>
TheAbstractTestDefinition class is responsible for specifying each Step class as@SpringBootTest andits@ContextConfiguration
All the
Step Classesin the Framework shouldextendtheAbstractTestDefinitionclass
@ContextConfiguration(classes = {FrameworkContextConfiguration.class})@SpringBootTestpublicclassAbstractTestDefinition {}
TheFrameworkContextConfiguration class is responsible for specifying the Spring@Configuration, modules to scan,properties to use etc
@EnableRetry@Configuration@ComponentScan({"com.cmccarthy.ui","com.cmccarthy.common"})@PropertySource("application.properties")publicclassFrameworkContextConfiguration {}
There is only one thing you need to do to switch the environment - which is to set<activeByDefault> property in theMaster POM.
By default, the value of
spring.profiles.activeis defined in theapplication.propertiesfile which inherits itsvalue from the Master POM property<activeByDefault>
<profiles> ... <profile> <id>prod</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <activatedProperties>prod</activatedProperties> </properties> </profile> ...</profiles>
You can then specify the profile to use when running Maven from the command line like so:
mvn clean install -P devBelow is an example of theapplication.properties file.
spring.profiles.active=@activatedProperties@The Framework usesSpark Reports Framework togenerate the HTML Test Reports
The example below is a report generated by Extent Reports open-source library.
The Framework usesAllure Reports to generate the HTML Test Reports
The example below is a report generated by Allure Reports open-source library.
To generate the above report navigate to the root directory of the module under test and execute the following command
mvn allure:serve ormvn allure:generate (for an offline report)
The Framework usesLogback You can instantiate the logging service in any Classlike so
privatefinalLoggerlogger=LoggerFactory.getLogger(WikipediaPageSteps.class);
you can then use the logger like so :
logger.info("This is a info message");logger.warn("This is a warning message");logger.debug("This is a info message");logger.error("This is a error message");
TheLog4j2 logging service is initialized from theHooks.class
publicclassHooks {@AutowiredprivateHookUtilshookUtil;@AfterpublicvoidafterScenario(Scenarioscenario) {hookUtil.endOfTest(scenario); }}
Rest Assured IO is used to map theResponse Objects to their respectivePOJO Classes
<dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>3.0.0</version></dependency>
- Execute the following commands to resolve any dependency issues
cd ~/install directory path/spring-cucumber-junit-parallel-test-harnessmvn clean install -DskipTests
Spotted a mistake? Questions? Suggestions?
About
Spring, Cucumber, Java 17, JUnit 5, Logback and Extent Spark Reports basic test harness. Rest Assured and Selenium test examples provided
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.

