0% found this document useful (0 votes)
64 views

Exercise Sheet 4: November 13Th: Junit

This document provides exercises to extend the JUnit testing framework. Exercise 1 involves filling gaps in the core JUnit source code. Exercise 2 involves extending JUnit with conditional test cases, performance measurement, and performance testing. Exercise 3 involves building a test suite tree and investigating issues that can occur, such as adding a test suite to itself or adding a test without a name. Design patterns used include ConditionalTestCase and observing potential bugs or unsafe code.

Uploaded by

Sun Java
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Exercise Sheet 4: November 13Th: Junit

This document provides exercises to extend the JUnit testing framework. Exercise 1 involves filling gaps in the core JUnit source code. Exercise 2 involves extending JUnit with conditional test cases, performance measurement, and performance testing. Exercise 3 involves building a test suite tree and investigating issues that can occur, such as adding a test suite to itself or adding a test without a name. Design patterns used include ConditionalTestCase and observing potential bugs or unsafe code.

Uploaded by

Sun Java
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

HIS POS

Wintersemester 2014/2015
Fachbereich 2

Exercise Sheet 4
Prof. Dr. Jrg Schfer

Exercise Sheet 4
November 13th: JUnit
Note: You can use JUnit (V <= 3.8) for exercise 2 and 3 or (better) my source code of the core
classes for all exercises of this sheet!
Exercise 1
Fill the gaps in my source code of the core classes of JUnit (JUnit.zip).
Exercise 2
a) Extend JUnit with Conditional Test Cases:
1. Implement a ConditionalTestCase extending TestCase to support a public boolean
shouldRun() method. Subclasses can override the default and henceforth developers can
ex- or include certain test cases depending on context (i.e. for different platforms etc.)
2. What Design Patterns are in action here?
b) Extend JUnit with Performance Measurement:
1. Add code to ConditionalTestCase to automatically measure execution time of test methods!
2. Where would you put the results?
c) Extend JUnit with Performance Testing:
1. Add code to ConditionalTestCase to automatically test execution time of test methods!
If execution takes too long, throw an AssertionFailedError with a proper message!
2. Which Design Pattern are you using?
Exercise 3
a) Build a TestSuite tree by executing code like:
public static
TestSuite
TestSuite
TestSuite

void main(String[] args) {


suite1 = new TestSuite(MyTestCase.class);
suite2 = new TestSuite(MyTestCase.class);
suite3 = new TestSuite(MyTestCase.class);

// Dont uncomment next line ;-)


// suite1.addTest(suite1);
suite1.addTest(suite2);
suite2.addTest(suite3);
Test test = new MyTestCase("testMethod");
suite1.addTest(test);
test = new MyTestCase("testMethod");
suite2.addTest(test);
test = new MyTestCase();
//this fails Nullpointer Execption!
//suite3.addTest(test);

1/2

HIS POS
Wintersemester 2014/2015
Fachbereich 2

Exercise Sheet 4
Prof. Dr. Jrg Schfer

junit.textui.TestRunner.run(suite1);
}
b)

1. What happens if TestSuite adds itself?


2. What can one do to make code safer?
3. Is this a bug?

c)

1. What happens if you execute code like suite3.addTest(test);?


2. Is this a bug?
3. What is the root cause for this behavior?

Hints
Consult the literature!
You can work in pairs, if you want!
If you want to learn a Java API, look into the java docs!
Always use the same familiar IDE (suggestion Eclipse)!

2/2

You might also like