Code Monkey home page Code Monkey logo

spring-cucumber-junit-parallel-test-harness's Introduction

Spring Cucumber Junit Parallel Test Harness

Build Status Codacy Badge

Index

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 |

Maven

The Framework uses Spring Boot Test , Cucumber , Rest Assured and Selenium 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>

Quickstart

JUnit 5

By using the JUnit and the Cucumber JVM @Cucumber Annotation Type we can specify our Cucumber Options like so :

cucumber.execution.parallel.enabled=true
cucumber.execution.parallel.config.strategy=fixed
cucumber.execution.parallel.config.fixed.parallelism=5
cucumber.plugin=io.qameta.allure.cucumber6jvm.AllureCucumber6Jvm,com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:,pretty,json:target/cucumber/report.json,

Right click the WeatherRunnerTest or class and select Run

@Cucumber
public class WeatherRunnerTest {
}

Command Line

Normally you will use your IDE to run a *.feature file directly or via the *Test.java class. With the Test class, we can run tests from the command-line as well.

Note that the mvn 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=WeatherRunnerTest
mvn test -Dtest=JunitSuiteTest

Note that the mvn clean install command runs all test Classes that follow the *Test.java naming convention

mvn clean install

IDE Support

To minimize the discrepancies between IDE versions and Locales the <sourceEncoding> is set to UTF-8

<properties>
    ...
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    ...
</properties>

Java JDK

The Java version to use is defined in the maven-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>

Configuration

The AbstractTestDefinition class is responsible for specifying each Step class as @SpringBootTest and its @ContextConfiguration

All the Step Classes in the Framework should extend the AbstractTestDefinition class

@ContextConfiguration(classes = {FrameworkContextConfiguration.class})
@SpringBootTest
public class AbstractTestDefinition {
}

The FrameworkContextConfiguration 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")
public class FrameworkContextConfiguration {
}

Environment Switching

There is only one thing you need to do to switch the environment - which is to set <activeByDefault> property in the Master POM.

By default, the value of spring.profiles.active is defined in the application.properties file which inherits its value 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 dev

Below is an example of the application.properties file.

spring.profiles.active=@activatedProperties@

Extent Spark Reports

The Framework uses Spark Reports Framework to generate the HTML Test Reports

The example below is a report generated by Extent Reports open-source library.

Allure Reports

The Framework uses Allure 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 or mvn allure:generate (for an offline report)

Logging

The Framework uses Logback You can instantiate the logging service in any Class like so

private final Logger logger=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");

Before / After Hooks

The Log4j2 logging service is initialized from the Hooks.class

public class Hooks {

    @Autowired
    private HookUtils hookUtil;

    @After
    public void afterScenario(Scenario scenario) {
        hookUtil.endOfTest(scenario);
    }
}

JSON Transforms

Rest Assured IO is used to map the Response Objects to their respective POJO Classes

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.0</version>
</dependency>

Troubleshooting

  • Execute the following commands to resolve any dependency issues
    1. cd ~/install directory path/spring-cucumber-junit-parallel-test-harness
    2. mvn clean install -DskipTests

Contributing

Spotted a mistake? Questions? Suggestions?

Open an Issue

spring-cucumber-junit-parallel-test-harness's People

Contributors

cmccarthyirl avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.