How to use method of org.jmock.test.acceptance.junit4.FailureRecordingRunListener class

Best Jmock-library code snippet using org.jmock.test.acceptance.junit4.FailureRecordingRunListener.

Run Jmock-library automation tests on LambdaTest cloud grid

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

copy
1package org.jmock.test.acceptance.junit4;
2
3import static org.jmock.test.unit.support.AssertThat.stringIncludes;
4import junit.framework.TestCase;
5
6import org.jmock.test.acceptance.junit4.testdata.DerivedJUnit4TestThatDoesNotSatisfyExpectations;
7import org.jmock.test.acceptance.junit4.testdata.JUnit4TestThatAutoInstantiatesMocks;
8import org.jmock.test.acceptance.junit4.testdata.JUnit4TestThatCreatesNoMockery;
9import org.jmock.test.acceptance.junit4.testdata.JUnit4TestThatCreatesTwoMockeries;
10import org.jmock.test.acceptance.junit4.testdata.JUnit4TestThatDoesNotCreateAMockery;
11import org.jmock.test.acceptance.junit4.testdata.JUnit4TestThatDoesNotSatisfyExpectations;
12import org.jmock.test.acceptance.junit4.testdata.JUnit4TestThatDoesSatisfyExpectations;
13import org.jmock.test.acceptance.junit4.testdata.JUnit4TestThatThrowsExpectedException;
14import org.jmock.test.acceptance.junit4.testdata.JUnit4TestWithNonPublicBeforeMethod;
15
16public class JUnit4TestRunnerTests extends TestCase {
17    FailureRecordingRunListener listener = new FailureRecordingRunListener();
18    
19    public void testTheJUnit4TestRunnerReportsPassingTestsAsSuccessful() {
20        listener.runTestIn(JUnit4TestThatDoesSatisfyExpectations.class);
21        listener.assertTestSucceeded();
22    }
23    
24    public void testTheJUnit4TestRunnerAutomaticallyAssertsThatAllExpectationsHaveBeenSatisfied() {
25        listener.runTestIn(JUnit4TestThatDoesNotSatisfyExpectations.class);
26        listener.assertTestFailedWith(AssertionError.class);
27    }
28    
29    public void testTheJUnit4TestRunnerLooksForTheMockeryInBaseClasses() {
30        listener.runTestIn(DerivedJUnit4TestThatDoesNotSatisfyExpectations.class);
31        listener.assertTestFailedWith(AssertionError.class);
32    }
33    
34    public void testTheJUnit4TestRunnerReportsAHelpfulErrorIfTheMockeryIsNull() {
35        listener.runTestIn(JUnit4TestThatDoesNotCreateAMockery.class);
36        listener.assertTestFailedWith(IllegalStateException.class);
37    }
38    
39    // See issue JMOCK-156
40    public void testReportsMocksAreNotSatisfiedWhenExpectedExceptionIsThrown() {
41        listener.runTestIn(JUnit4TestThatThrowsExpectedException.class);
42        listener.assertTestFailedWith(AssertionError.class);
43    }
44
45    // See issue JMOCK-219
46    public void testTheJUnit4TestRunnerReportsIfNoMockeryIsFound() {
47        listener.runTestIn(JUnit4TestThatCreatesNoMockery.class);
48        listener.assertTestFailedWithInitializationError();
49    }
50
51    // See issue JMOCK-219
52    public void testTheJUnit4TestRunnerReportsIfMoreThanOneMockeryIsFound() {
53        listener.runTestIn(JUnit4TestThatCreatesTwoMockeries.class);
54        listener.assertTestFailedWithInitializationError();
55    }
56    
57    public void testDetectsNonPublicBeforeMethodsCorrectly() {
58        listener.runTestIn(JUnit4TestWithNonPublicBeforeMethod.class);
59        listener.assertTestFailedWith(Throwable.class);
60        stringIncludes("should have detected non-public before method", 
61                       "Method before() should be public", listener.failure.getMessage());
62    }
63    
64    public void testAutoInstantiatesMocks() {
65        listener.runTestIn(JUnit4TestThatAutoInstantiatesMocks.class);
66        listener.assertTestSucceeded();
67    }
68}
69
Full Screen
copy
1package org.jmock.test.acceptance.junit4;
2
3import junit.framework.TestCase;
4
5import org.jmock.test.acceptance.junit4.testdata.JUnit4WithRulesExamples;
6
7public class JUnit4WithRulesTestRunnerTests extends TestCase {
8    FailureRecordingRunListener listener = new FailureRecordingRunListener();
9    
10    public void testTheJUnit4TestRunnerReportsPassingTestsAsSuccessful() {
11        listener.runTestIn(JUnit4WithRulesExamples.SatisfiesExpectations.class);
12        listener.assertTestSucceeded();
13    }
14    
15    public void testTheJUnit4TestRunnerAutomaticallyAssertsThatAllExpectationsHaveBeenSatisfied() {
16        listener.runTestIn(JUnit4WithRulesExamples.DoesNotSatisfyExpectations.class);
17        listener.assertTestFailedWith(AssertionError.class);
18    }
19    
20    
21    public void testTheJUnit4TestRunnerLooksForTheMockeryInBaseClasses() {
22        listener.runTestIn(JUnit4WithRulesExamples.DerivedAndDoesNotSatisfyExpectations.class);
23        listener.assertTestFailedWith(AssertionError.class);
24    }
25
26    
27    // See issue JMOCK-156
28    public void testReportsMocksAreNotSatisfiedWhenExpectedExceptionIsThrown() {
29        listener.runTestIn(JUnit4WithRulesExamples.ThrowsExpectedException.class);
30        listener.assertTestFailedWith(AssertionError.class);
31    }
32    
33    public void testFailsWhenMoreThanOneJMockContextField() {
34        listener.runTestIn(JUnit4WithRulesExamples.CreatesTwoMockeries.class);
35        listener.assertTestFailedWith(AssertionError.class);
36    }
37
38    public void testAutoInstantiatesMocks() {
39        listener.runTestIn(JUnit4WithRulesExamples.AutoInstantiatesMocks.class);
40        listener.assertTestSucceeded();
41    }
42}
43
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 code on LambdaTest Cloud Grid

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