How to use exampleStarted method of net.thucydides.junit.listeners.TestCountListener class

Best Serenity JUnit code snippet using net.thucydides.junit.listeners.TestCountListener.exampleStarted

Run Serenity JUnit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package net.thucydides.junit.listeners;
2
3import net.thucydides.core.Thucydides;
4import net.thucydides.core.ThucydidesSystemProperty;
5import net.thucydides.core.logging.LoggingLevel;
6import net.thucydides.core.model.DataTable;
7import net.thucydides.core.model.Story;
8import net.thucydides.core.model.TestOutcome;
9import net.thucydides.core.statistics.TestCount;
10import net.thucydides.core.steps.ExecutedStepDescription;
11import net.thucydides.core.steps.StepFailure;
12import net.thucydides.core.steps.StepListener;
13import net.thucydides.core.util.EnvironmentVariables;
14import net.thucydides.junit.finder.TestFinder;
15import org.apache.commons.lang3.StringUtils;
16import org.slf4j.Logger;
17import org.slf4j.LoggerFactory;
18
19import java.util.Map;
20
21public class TestCountListener implements StepListener {
22
23    private final Logger logger;
24    private final EnvironmentVariables environmentVariables;
25    private final TestCount testCount;
26
27    protected TestCountListener(EnvironmentVariables environmentVariables, Logger logger, TestCount testCount) {
28        this.logger = logger;
29        this.environmentVariables = environmentVariables;
30        this.testCount = testCount;
31        logTotalTestCount();
32    }
33
34    public TestCountListener(EnvironmentVariables environmentVariables, TestCount testCount) {
35        this(environmentVariables, LoggerFactory.getLogger(Thucydides.class), testCount);
36    }
37
38    private void logTotalTestCount() {
39        String rootPackage = ThucydidesSystemProperty.THUCYDIDES_TEST_ROOT.from(environmentVariables);
40        if (StringUtils.isNotEmpty(rootPackage)) {
41            TestFinder finder = TestFinder.thatFinds().allTests().inPackage(rootPackage);
42            int testMethodCount = finder.countTestMethods();
43            if (loggingLevelIsAtLeast(LoggingLevel.NORMAL)) {
44                getLogger().info("PREPARING TO EXECUTE {} TESTS", testMethodCount);
45            }
46        }
47    }
48
49    private boolean loggingLevelIsAtLeast(LoggingLevel minimumLoggingLevel) {
50        return (getLoggingLevel().compareTo(minimumLoggingLevel) >= 0);
51    }
52
53    protected Logger getLogger() {
54        return logger;
55    }
56
57    private LoggingLevel getLoggingLevel() {
58        String logLevel = ThucydidesSystemProperty.THUCYDIDES_LOGGING.from(environmentVariables, LoggingLevel.NORMAL.name());
59
60        return LoggingLevel.valueOf(logLevel);
61    }
62
63
64    public void testSuiteStarted(Class<?> storyClass) {
65    }
66
67
68    public void testSuiteStarted(Story storyOrFeature) {
69    }
70
71
72    public void testSuiteFinished() {
73    }
74
75
76    public void testStarted(String description) {
77        int currentTestCount = testCount.getNextTest();
78        if (loggingLevelIsAtLeast(LoggingLevel.NORMAL)) {
79            getLogger().info("TEST NUMBER: {}", currentTestCount);
80        }
81    }
82
83
84    public void testFinished(TestOutcome result) {
85    }
86
87    public void testRetried() {
88    }
89
90    public void stepStarted(ExecutedStepDescription description) {
91    }
92
93
94    public void skippedStepStarted(ExecutedStepDescription description) {
95    }
96
97
98    public void stepFailed(StepFailure failure) {
99    }
100
101
102    public void lastStepFailed(StepFailure failure) {
103    }
104
105
106    public void stepIgnored() {
107    }
108
109    public void stepPending() {
110    }
111
112
113    public void stepPending(String message) {
114    }
115
116
117    public void stepFinished() {
118    }
119
120
121    public void testFailed(TestOutcome testOutcome, Throwable cause) {
122    }
123
124
125    public void testIgnored() {
126    }
127
128    @Override
129    public void testSkipped() {
130
131    }
132
133    @Override
134    public void testPending() {
135
136    }
137
138
139    public void notifyScreenChange() {
140    }
141
142    public void useExamplesFrom(DataTable table) {
143    }
144
145    public void exampleStarted(Map<String, String> data) {
146    }
147
148    public void exampleFinished() {
149    }
150
151    @Override
152    public void assumptionViolated(String message) {
153    }
154}
155
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger exampleStarted code on LambdaTest Cloud Grid

Execute automation tests with exampleStarted on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)