How to use fireTestFinished method of org.junit.runner.notification.RunNotifier class

Best junit code snippet using org.junit.runner.notification.RunNotifier.fireTestFinished

Run junit automation tests on LambdaTest cloud grid

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

copy
1package controller.exploration;
2
3import org.junit.runner.Description;
4import org.junit.runner.Result;
5import org.junit.runner.notification.Failure;
6import org.junit.runner.notification.RunListener;
7import org.junit.runner.notification.RunNotifier;
8import org.junit.runner.notification.StoppedByUserException;
9
10public class JUnit4WrappedRunNotifier extends RunNotifier {
11
12    private final RunNotifier notifier;
13
14    private boolean testExpStarted;
15
16    private Description runningTestDescription;
17
18    private Failure testFailure;
19
20    public JUnit4WrappedRunNotifier(RunNotifier notifier) {
21        this.notifier = notifier;
22    }
23
24    /**
25     * test exploration is starting reset failed status
26     */
27    public void testExplorationStarted() {
28        this.testExpStarted = true;
29        this.testFailure = null;
30    }
31
32    /**
33     * Only fire started event if the exploration is starting
34     */
35    @Override
36    public void fireTestStarted(Description description) throws StoppedByUserException {
37        if (this.testExpStarted) {
38            this.notifier.fireTestStarted(description);
39            this.runningTestDescription = description;
40            // No longer starting
41            this.testExpStarted = false;
42        }
43    }
44
45    /**
46     * Intercept test failure
47     */
48    @Override
49    public void fireTestAssumptionFailed(Failure failure) {
50        this.notifier.fireTestAssumptionFailed(failure);
51        this.testFailure = failure;
52    }
53
54    /**
55     * Intercept test failure
56     */
57    @Override
58    public void fireTestFailure(Failure failure) {
59        this.notifier.fireTestFailure(failure);
60        this.testFailure = failure;
61    }
62    
63    public void setFailure(Failure failure) {
64        this.testFailure = failure;
65    }
66
67    /**
68     * Return current test's failure status
69     * 
70     * @return current test's failure status
71     */
72    public boolean isTestFailed() {
73        return this.testFailure != null;
74    }
75    
76    /**
77     * Return current test's failure object
78     * 
79     * @return current test's failure object
80     */
81    public Failure getFailure() {
82        return this.testFailure;
83    }
84
85    /**
86     * Do not fire test finished event until exploration is finished.
87     */
88    @Override
89    public void fireTestFinished(Description description) {
90        // Will be fired when exploration is completed.
91    }
92
93    /**
94     * Fires the test finished event.
95     */
96    public void testExplorationFinished() {
97        this.notifier.fireTestFinished(this.runningTestDescription);
98    }
99
100    /*
101     * (non-Javadoc)
102     * 
103     * @see
104     * org.junit.runner.notification.RunNotifier#fireTestIgnored(org.junit.runner
105     * .Description)
106     */
107    @Override
108    public void fireTestIgnored(Description description) {
109        this.notifier.fireTestIgnored(description);
110    }
111
112    /*
113     * (non-Javadoc)
114     * 
115     * @see
116     * org.junit.runner.notification.RunNotifier#addFirstListener(org.junit.
117     * runner.notification.RunListener)
118     */
119    @Override
120    public void addFirstListener(RunListener listener) {
121        this.notifier.addFirstListener(listener);
122    }
123
124    /*
125     * (non-Javadoc)
126     * 
127     * @see
128     * org.junit.runner.notification.RunNotifier#addListener(org.junit.runner
129     * .notification.RunListener)
130     */
131    @Override
132    public void addListener(RunListener listener) {
133        this.notifier.addListener(listener);
134    }
135
136    /*
137     * (non-Javadoc)
138     * 
139     * @see
140     * org.junit.runner.notification.RunNotifier#fireTestRunFinished(org.junit
141     * .runner.Result)
142     */
143    @Override
144    public void fireTestRunFinished(Result result) {
145        this.notifier.fireTestRunFinished(result);
146    }
147
148    /*
149     * (non-Javadoc)
150     * 
151     * @see
152     * org.junit.runner.notification.RunNotifier#fireTestRunStarted(org.junit
153     * .runner.Description)
154     */
155    @Override
156    public void fireTestRunStarted(Description description) {
157        this.notifier.fireTestRunStarted(description);
158    }
159
160    /*
161     * (non-Javadoc)
162     * 
163     * @see org.junit.runner.notification.RunNotifier#pleaseStop()
164     */
165    @Override
166    public void pleaseStop() {
167        this.notifier.pleaseStop();
168    }
169
170    /*
171     * (non-Javadoc)
172     * 
173     * @see
174     * org.junit.runner.notification.RunNotifier#removeListener(org.junit.runner
175     * .notification.RunListener)
176     */
177    @Override
178    public void removeListener(RunListener listener) {
179        this.notifier.removeListener(listener);
180    }
181
182}
183
Full Screen
copy
1// Copyright 2015 The Bazel Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//    http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.testing.junit.junit4.runner;
16
17import org.junit.runner.Description;
18import org.junit.runner.Result;
19import org.junit.runner.notification.Failure;
20import org.junit.runner.notification.RunListener;
21import org.junit.runner.notification.RunNotifier;
22import org.junit.runner.notification.StoppedByUserException;
23
24/**
25 * A {@link RunNotifier} that delegates all its operations to another {@code RunNotifier}.
26 * This class is meant to be overridden to modify some behaviors.
27 */
28public abstract class RunNotifierWrapper extends RunNotifier {
29  private final RunNotifier delegate;
30
31  /**
32   * Creates a new instance.
33   *
34   * @param delegate notifier to delegate to
35   */
36  public RunNotifierWrapper(RunNotifier delegate) {
37    this.delegate = delegate;
38  }
39
40  /**
41   * @return the delegate
42   */
43  protected final RunNotifier getDelegate() {
44    return delegate;
45  }
46
47  @Override
48  public void addFirstListener(RunListener listener) {
49    delegate.addFirstListener(listener);
50  }
51
52  @Override
53  public void addListener(RunListener listener) {
54    delegate.addListener(listener);
55  }
56
57  @Override
58  public void removeListener(RunListener listener) {
59    delegate.removeListener(listener);
60  }
61
62  @Override
63  public void fireTestRunStarted(Description description) {
64    delegate.fireTestRunStarted(description);
65  }
66  
67  @Override
68  public void fireTestStarted(Description description) throws StoppedByUserException {
69    delegate.fireTestStarted(description);
70  }
71  
72  @Override
73  public void fireTestIgnored(Description description) {
74    delegate.fireTestIgnored(description);
75  }
76
77  @Override
78  public void fireTestAssumptionFailed(Failure failure) {
79    delegate.fireTestAssumptionFailed(failure);
80  }
81
82  @Override
83  public void fireTestFailure(Failure failure) {
84    delegate.fireTestFailure(failure);
85  }
86
87  @Override
88  public void fireTestFinished(Description description) {
89    delegate.fireTestFinished(description);
90  }
91
92  @Override
93  public void fireTestRunFinished(Result result) {
94    delegate.fireTestRunFinished(result);
95  }
96
97  @Override
98  public void pleaseStop() {
99    delegate.pleaseStop();
100  }
101}
102
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 fireTestFinished code on LambdaTest Cloud Grid

Execute automation tests with fireTestFinished 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)