How to use createResult method of junit.framework.TestCase class

Best junit code snippet using junit.framework.TestCase.createResult

Run junit automation tests on LambdaTest cloud grid

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

copy
1package org.bitcamp.ex11;
2
3import junit.framework.AssertionFailedError;
4import junit.framework.Test;
5import junit.framework.TestCase;
6import junit.framework.TestListener;
7import junit.framework.TestResult;
8
9public class Chapter11 extends TestCase {
10
11	public void testChapter11() {
12		System.out.println("- TestCase::testChapter11() invoked.");
13		
14		System.out.println("Hello");
15		
16//		throw new RuntimeException("testChapter11");
17		
18		assertTrue(false);
19		
20	} // testChapter11
21
22	@Override
23	public int countTestCases() {
24//		System.out.println("- TestCase::countTestCase() invoked.");
25		return super.countTestCases();
26	}
27
28	@Override
29	protected TestResult createResult() {
30		System.out.println("- TestCase::createResult() invoked.");
31		return super.createResult();
32	}
33
34	@Override
35	public TestResult run() {
36		System.out.println("- TestCase::run() invoked.");
37		return super.run();
38	}
39
40	@Override
41	public void run(TestResult result) {
42		System.out.println("- TestCase::run("+result+") invoked.");
43		
44		result.addListener(new TestListener() {
45
46			@Override
47			public void addError(Test test, Throwable t) {
48				System.out.println("\t- TestListender::addError("+test+","+t+") invoked.");
49				
50			}
51
52			@Override
53			public void addFailure(Test test, AssertionFailedError t) {
54				System.out.println("\t- TestListender::addFailure("+test+","+t+") invoked.");
55				
56			}
57
58			@Override
59			public void endTest(Test test) {
60				System.out.println("\t- TestListender::endTest("+test+") invoked.");
61				
62			}
63
64			@Override
65			public void startTest(Test test) {
66				System.out.println("\t- TestListender::startTest("+test+") invoked.");
67				
68			} // startTest
69			
70		}); //addListener
71		
72		super.run(result);
73	}
74
75	@Override
76	public void runBare() throws Throwable {
77		System.out.println("- TestCase::runBare() invoked.");
78		super.runBare();
79	}
80
81	@Override
82	protected void runTest() throws Throwable {
83		System.out.println("- TestCase::runTest() invoked.");
84		super.runTest();
85	}
86
87	@Override
88	protected void setUp() throws Exception {
89		System.out.println("- TestCase::setUp() invoked.");
90		super.setUp();
91	}
92
93	@Override
94	protected void tearDown() throws Exception {
95		System.out.println("- TestCase::tearDown() invoked.");
96		super.tearDown();
97	}
98
99	@Override
100	public String getName() {
101//		System.out.println("- TestCase::getName() invoked.");
102		return super.getName();
103	}
104
105	@Override
106	public void setName(String name) {
107		System.out.println("- TestCase::setName("+name+") invoked.");
108		super.setName(name);
109	}
110}
111
Full Screen
copy
1/**
2 * 
3 */
4package com.palmcommerce.funds.protocol.parser;
5
6import org.apache.commons.logging.Log;
7import org.apache.commons.logging.LogFactory;
8
9import com.palmcommerce.funds.protocol.parser.exception.ProtocolParserException;
10
11import junit.framework.TestCase;
12import junit.framework.TestResult;
13
14/**
15 * @author sparrow
16 *
17 */
18public class DefaultProtocolParserTest extends TestCase {
19	private static final Log logger=LogFactory.getLog(DefaultProtocolParserTest.class);
20	IProtocolParser parser;
21	/**
22	 * @param name
23	 */
24	public DefaultProtocolParserTest(String name) {
25		super(name);
26	}
27
28	/* (non-Javadoc)
29	 * @see junit.framework.TestCase#setUp()
30	 */
31	protected void setUp() throws Exception {
32		super.setUp();
33		parser=ProtocolParserFactory.getFactory().getParser();//new DefaultProtocolParser();
34		
35	}
36	
37	public void testParser() throws ProtocolParserException{
38		
39		String content="240001|0000030049|0001|0100000001|lisi|1|532923197802050038|0||20090420|";
40
41		String[] result=parser.parse(content);
42		
43		logger.info("Size:"+result.length);
44		for(String element:result){
45			logger.info("----"+element);
46		}
47		
48		assertTrue(result.length==10);
49	}
50
51	@Override
52	protected TestResult createResult() {
53		// TODO Auto-generated method stub
54		return super.createResult();
55	}
56
57	/* (non-Javadoc)
58	 * @see junit.framework.TestCase#tearDown()
59	 */
60	protected void tearDown() throws Exception {
61		super.tearDown();
62	}
63
64}
65
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 createResult code on LambdaTest Cloud Grid

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