View on GitHub

Cucumber Reports

BeforeSuite and AfterSuite methods

Download this project as a .zip file Download this project as a tar.gz file

Where is it used?

Standard Cucumber runner has functionality of hooks which is represented with @Before and @After annotations and which are running before and after each scenario respectively. But there are some cases when we need to perform some global setup/cleanup. Thus we need some additional hooks which provide such capabilities. As the part of Extended Cucumber Runner there are 2 additional annotations introduced. They are:

  • @BeforeSuite - annotates method which is supposed to run before the entire test suite starts
  • @AfterSuite - annotates method which is supposed to run after the entire test suite ends

How to use it?

The above annotations should be applied to the main test class where ExtendedCucumber runner is applied to. Here is some sample code showing the use of global setup/tear down methods:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.github.mkolisnyk.cucumber.reporting;

import org.junit.runner.RunWith;

import com.github.mkolisnyk.cucumber.runner.AfterSuite;
import com.github.mkolisnyk.cucumber.runner.BeforeSuite;
import com.github.mkolisnyk.cucumber.runner.ExtendedCucumber;
import com.github.mkolisnyk.cucumber.runner.ExtendedCucumberOptions;

import cucumber.api.CucumberOptions;

@RunWith(ExtendedCucumber.class)
@ExtendedCucumberOptions(jsonReport = "target/cucumber.json",
        retryCount = 3,
        detailedReport = true,
        detailedAggregatedReport = true,
        overviewReport = true,
        toPDF = true,
        outputFolder = "target")
@CucumberOptions(plugin = { "html:target/cucumber-html-report",
        "json:target/cucumber.json", "pretty:target/cucumber-pretty.txt",
        "usage:target/cucumber-usage.json", "junit:target/cucumber-results.xml" },
        features = { "./src/test/java/com/github/mkolisnyk/cucumber/features" },
        glue = { "com/github/mkolisnyk/cucumber/steps" })
public class SampleCucumberTest {
	@BeforeSuite
	public static void setUp() {
		// TODO: Add setup code
	}
	@AfterSuite
	public static void tearDown() {
		// TODO: Add tear down code
	}
}

Note that methods which have @BeforeSuite and @AfterSuite annotations asigned must be static as at the state we run those methods there is no information about running class available.

Related Links

News