How to use method of org.jmock.test.unit.internal.FailingExampleTestCase class

Best Jmock-library code snippet using org.jmock.test.unit.internal.FailingExampleTestCase.

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.unit.internal;
2
3
4/**
5 * This class is not meant to run as a standalone test,
6 * but rather as input to other tests.
7 *
8 * @author Steve Freeman 2012 http://www.jmock.org
9 */
10public abstract class FailingExampleTestCase extends VerifyingTestCase {
11    public static final Exception tearDownException = new Exception("tear down");
12    public static final Exception testException = new Exception("test");
13
14    public FailingExampleTestCase(String testName) {
15        super(testName);
16    }
17
18    @Override public void tearDown() throws Exception {
19        throw tearDownException;
20
21    }
22
23    public void testDoesNotThrowException() throws Exception {
24        // no op
25    }
26
27    public void testThrowsExpectedException() throws Exception {
28        throw testException;
29    }
30}
31
Full Screen
copy
1/*  Copyright (c) 2000-2006 jMock.org
2 */
3package org.jmock.test.unit.internal;
4
5import junit.framework.TestCase;
6
7public class VerifyingTestCaseTests extends TestCase {
8    public static class ExampleTestCase extends VerifyingTestCase {
9        public ExampleTestCase() {
10            setName("testMethod");
11        }
12        
13        public void testMethod() {
14            // Success!
15        }
16    }
17    
18    public void testCanBeConstructedWithAName() {
19        String name = "NAME";
20
21        VerifyingTestCase testCase = new VerifyingTestCase(name) {
22        };
23
24        assertEquals("name", name, testCase.getName());
25    }
26
27    private boolean verifierWasRun = false;
28    
29    public void testRunsVerifiersAfterTest() throws Throwable {
30        ExampleTestCase testCase = new ExampleTestCase();
31        
32        testCase.addVerifier(new Runnable() {
33            public void run() {
34                verifierWasRun = true;
35            }
36        });
37        
38        testCase.runBare();
39        
40        assertTrue(verifierWasRun);
41    }
42
43    public void testOverridingRunTestDoesNotAffectVerification() throws Throwable {
44        ExampleTestCase testCase = new ExampleTestCase() {
45            @Override
46            public void runTest() {
47            }
48        };
49        
50        testCase.addVerifier(new Runnable() {
51            public void run() {
52                verifierWasRun = true;
53            }
54        });
55        
56        testCase.runBare();
57        
58        assertTrue(verifierWasRun);
59    }
60    
61    public void testOverridingSetUpAndTearDownDoesNotAffectVerification() throws Throwable {
62        ExampleTestCase testCase = new ExampleTestCase() {
63            @Override public void setUp() { }
64
65            @Override public void tearDown() { }
66        };
67
68        testCase.addVerifier(new Runnable() {
69            public void run() {
70                verifierWasRun = true;
71            }
72        });
73        
74        testCase.runBare();
75        
76        assertTrue(verifierWasRun);
77    }
78
79  public void testThrowsTestExceptionRatherThanTearDownException() throws Throwable {
80        try {
81            new FailingExampleTestCase("testThrowsExpectedException") {}.runBare();
82            fail("should have thrown exception");
83        } catch (Exception actual) {
84            assertSame(FailingExampleTestCase.testException, actual);
85        }
86    }
87
88    public void testThrowsTearDownExceptionWhenNoTestException() throws Throwable {
89        try {
90            new FailingExampleTestCase("testDoesNotThrowException") {}.runBare();
91            fail("should have thrown exception");
92        } catch (Exception actual) {
93            assertSame(FailingExampleTestCase.tearDownException, actual);
94        }
95    }
96
97}
98
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)