Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cmccarthyirl/spring-cucumber-serenity-test-harness

Test framework that uses Spring, Serenity-Cucumber, Java 17, JUnit 5 and SLF4J to provide a basic harness. SerenityRest and Serenity Webdriver test examples provided
https://github.com/cmccarthyirl/spring-cucumber-serenity-test-harness

java java-17 serenity serenity-aggregate serenity-bdd serenity-cucumber serenity-restassured serenity-screenplay serenity-ui spring spring-boot spring-boot-test

Last synced: 8 days ago
JSON representation

Test framework that uses Spring, Serenity-Cucumber, Java 17, JUnit 5 and SLF4J to provide a basic harness. SerenityRest and Serenity Webdriver test examples provided

Awesome Lists containing this project

README

        

# Spring Cucumber Serenity Test Harness

# Index

Start

| Maven
| Quickstart |

Run

| Command Line
| IDE Support
| Java JDK
| Troubleshooting |

Report

| Configuration
| Environment Switching
| Serenity Reports
| Logging |

Advanced

| Before / After Hooks
| JSON Transforms
| Contributing |

# Maven

The Framework uses [Spring Boot Test](https://spring.io/guides/gs/testing-web/)
, [Cucumber](https://cucumber.io/) and [Serenity](http://www.thucydides.info/#/) client implementations.

Spring ``:

```xml

...

org.springframework.amqp
spring-rabbit
${spring-rabbit.version}


org.springframework.boot
spring-boot-starter-test


org.springframework
spring-test

...

```

Serenity ``:

```xml

...

net.serenity-bdd
serenity-core
${serenity.version}
test


net.serenity-bdd
serenity-junit
${serenity.version}
test


net.serenity-bdd
serenity-screenplay
${serenity.version}
test


net.serenity-bdd
serenity-screenplay-webdriver
${serenity.version}
test


net.serenity-bdd
serenity-ensure
${serenity.version}
test


net.serenity-bdd
serenity-cucumber6
${serenity.cucumber.version}
test


net.serenity-bdd
serenity-rest-assured
2.2.12


net.serenity-bdd
serenity-spring
2.2.12

...

```

# Quickstart

- [Intellij IDE](https://www.jetbrains.com/idea/) - `Recommended`
- [Java JDK 11](https://www.oracle.com/ie/java/technologies/javase-jdk11-downloads.html)
- [Apache Maven 3.6.3](https://maven.apache.org/docs/3.6.3/release-notes.html)

# JUnit

By using the [JUnit Framework](https://junit.org/junit4/) `@RunWith` Annotation Type we can utilize [Serenity](http://www.thucydides.info/#/) and [Cucumber](https://cucumber.io/) `@CucumberOptions` Annotation Type to execute the `*.feature`
file tests

> Right click the `WeatherTest` class and select `Run`

```java
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
plugin = {"pretty", "json:target/cucumber/report.json"},
features = "src/test/resources/features/WeatherTest.feature",
glue = {"com/cmccarthy/api", "com/cmccarthy/common"}
)
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=WeatherTest
```

```
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 `` is set to `UTF-8`

```xml

...
UTF-8
UTF-8
...

```

# Java JDK

The Java version to use is defined in the `maven-compiler-plugin`

```xml

...


...

org.apache.maven.plugins
maven-compiler-plugin

11
11


...


...

```

# 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

```java

@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

```java

@EnableRetry
@Configuration
@ComponentScan({
"com.cmccarthy"
})
@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 `` 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 ``

```xml

...

prod

true


prod


...

```

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.

```properties
spring.profiles.active=@activatedProperties@
```

# Serenity Reports

The Framework uses [Serenity Reports](https://serenity-bdd.github.io/theserenitybook/latest/extended-reports.html) to
generate the HTML Test Reports

> To generate the Serenity Reports execute the following from the command line
```
mvn serenity:aggregate
```
The example below is a report generated by Serenity Reports open-source library.

# Logging

The Framework uses [Log4j2](https://logging.apache.org/log4j/2.x/) You can instantiate the logging service in any Class
like so

```java
private final Logger logger=LoggerFactory.getLogger(WikipediaPageSteps.class);
```

you can then use the logger like so :

```java
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](https://logging.apache.org/log4j/2.x/) logging service is initialized from the `Hooks.class`

```java
public class Hooks {

@Autowired
private HookUtils hookUtil;

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

# JSON Transforms

[Rest Assured IO](https://rest-assured.io/) is used to map the `Response` Objects to their respective `POJO` Classes

```xml

io.rest-assured
rest-assured
3.0.0

```

# Troubleshooting

- Execute the following commands to resolve any dependency issues
1. `cd ~/spring-cucumber-serenity-test-harness`
2. `mvn clean install -DskipTests`

# Contributing

Spotted a mistake? Questions? Suggestions?

[Open an Issue](https://github.com/cmccarthyIrl/spring-cucumber-serenity-test-harness/issues)