Introduction to JUnit - ecourse2.ccu.edu.tw
Transcript of Introduction to JUnit - ecourse2.ccu.edu.tw
![Page 1: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/1.jpg)
Introduction to JUnit
Nai-Wei Lin
Department of Computer Science and
Software Engineering
National Chung Cheng University
![Page 2: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/2.jpg)
2
Content
JUnit framework
Test classes and test methods
Assert methods
Test driven development
![Page 3: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/3.jpg)
JUnit Framework
JUnit is an open source framework that has
been designed for the purpose of writing and
running tests in the Java programming
language.
JUnit is a regression testing framework for
unit testing.
3
![Page 4: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/4.jpg)
Test Classes and Test Methods
For each class C under test, define a test
class CTest.
Test classes inherit class TestCase in
package junit.framework.
For each method m under test, define a test
method testM.
Return type of a test method must be void.
Test method must not have any parameter.
Test method must not throw any exception.
4
![Page 5: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/5.jpg)
An Example
5
class Calculator
{
public int sum(int n1, int n2) { return n1+n2; }
}
import junit.framework.TestCase;
class CalculatorTest extends TestCase {
public void testSum() { /* test sum()
Calculator cal = new Calculator();
assertEquals(2, cal.sum(1,1));
}
}
![Page 6: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/6.jpg)
Assert Methods
assertEquals(expected, actual)If actual equals expected then does nothing; otherwise, fails.
assertEquals(message, expected, actual)If actual equals expected then does nothing; otherwise, fails and prints out message.
assertEquals(expected, actual, delta)If actual equals expected within delta then does nothing; otherwise, fails.
assertEquals(message, expected, actual, delta).
6
![Page 7: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/7.jpg)
Assert Methods
assertFalse(condition)If condition is false then does nothing; otherwise, fails.
assertFalse(message, condition).
assertTrue(condition) If condition is true then does nothing; otherwise, fails.
assertTrue(message, condition).
7
![Page 8: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/8.jpg)
Assert Methods
AssertNull(object)If object does not exist then does nothing; otherwise, fails.
AssertNull(message, object).
AssertNotNull(object)If object exists then does nothing; otherwise, fails.
AssertNotNull(message, object).
8
![Page 9: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/9.jpg)
Assert Methods
AssertSame(expected, actual)If actual and expected refer to the same object then does nothing; otherwise, fails.
AssertSame(message, expected, actual)
AssertNotSame(expected, actual)If actual and expected don’t refer to the same object then does nothing; otherwise, fails.
AssertNotSame(message, expected, actual)
9
![Page 10: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/10.jpg)
Test Driven Development
The test class is developed before the class
under test.
The development of the class under test
terminates if all test methods in the test class
succeed.
10
![Page 11: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/11.jpg)
An Example
11
class Complex
{ // an abstract data type
private float re;
private float im;
public Complex() { … }
public Complex(float r, float i) { … }
public float getRe() { … }
public float getIm() { … }
public boolean equals(Complex c) { … }
public Complex add(Complex c) { … }
public Complex sub(Complex c) { … }
public Complex mul(Complex c) { … }
public Complex div(Complex c)
throws DivByZeroException { … }
public String toString() { … }
}
![Page 12: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/12.jpg)
An Example
12
class ComplexTest extends TestCase {
public void testComplex() { … }
public void testEquals() { … }
public void testAdd() { … }
public void testSub() { … }
public void testMul() { … }
public void testDiv() { … }
public void testToString() { … }
…
}
![Page 13: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/13.jpg)
An Example
Create a new Java project “Complex”.
13
![Page 14: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/14.jpg)
14
![Page 15: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/15.jpg)
15
![Page 16: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/16.jpg)
16
![Page 17: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/17.jpg)
17
![Page 18: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/18.jpg)
An Example
Create a new source folder “test”.
18
![Page 19: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/19.jpg)
19
![Page 20: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/20.jpg)
20
![Page 21: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/21.jpg)
21
![Page 22: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/22.jpg)
An Example
Create a new JUnit Test Case “ComplexTest”
in source folder “test”.
If JUnit was not on the build path, then add
Junit on the build path.
22
![Page 23: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/23.jpg)
23
![Page 24: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/24.jpg)
24
![Page 25: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/25.jpg)
25
![Page 26: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/26.jpg)
26
![Page 27: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/27.jpg)
An Example
getRe() and getIm() can be generated
automatically.
There is no need to test getRe() and getIm().
Change method “test” to “testComplex”.
Use getRe(), getIm(), and assertEquals() to
test constructors Complex().
27
![Page 28: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/28.jpg)
An Example
28
public void testComplex() {
Complex c1 = new Complex();
Complex c2 = new Complex(2.0, 3.0);
assertEquals(0.0, c1.getRe(), 0.001);
assertEquals(0.0, c1.getIm(), 0.001);
assertEquals(2.0, c2.getRe(), 0.001);
assertEquals(3.0, c2.getIm(), 0.001);
}
![Page 29: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/29.jpg)
29
![Page 30: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/30.jpg)
An Example
Automatically generate the frame of the class
“Complex” in source folder “src” using quick
fix.
30
![Page 31: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/31.jpg)
31
![Page 32: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/32.jpg)
32
![Page 33: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/33.jpg)
33
![Page 34: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/34.jpg)
34
![Page 35: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/35.jpg)
An Example
Automatically generate the frame of the
constructor Complex(double r, double i) in
source folder “src” using quick fix.
35
![Page 36: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/36.jpg)
36
![Page 37: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/37.jpg)
37
![Page 38: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/38.jpg)
38
![Page 39: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/39.jpg)
An Example
Implement Complex(double r, double i).
39
![Page 40: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/40.jpg)
40
![Page 41: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/41.jpg)
An Example
Create fields “re” and “im” using quick fix.
41
![Page 42: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/42.jpg)
42
![Page 43: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/43.jpg)
43
![Page 44: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/44.jpg)
44
![Page 45: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/45.jpg)
An Example
Automatically generate getters and setters.
45
![Page 46: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/46.jpg)
46
![Page 47: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/47.jpg)
47
![Page 48: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/48.jpg)
48
![Page 49: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/49.jpg)
49
![Page 50: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/50.jpg)
An Example
Automatically generate the frame of the
constructor Complex() in source folder “src”
using quick fix.
50
![Page 51: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/51.jpg)
51
![Page 52: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/52.jpg)
52
![Page 53: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/53.jpg)
53
![Page 54: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/54.jpg)
An Example
Implement Complex().
54
![Page 55: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/55.jpg)
55
![Page 56: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/56.jpg)
56
![Page 57: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/57.jpg)
An Example
Run As JUnit Test
Repeatly modify the constructor until it
passes the test.
57
![Page 58: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/58.jpg)
58
![Page 59: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/59.jpg)
59
![Page 60: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/60.jpg)
An Example
Use Complex(), getRe() and getIm() to test
equals().
Use Complex(), getRe() and getIm(), and
equals() to test other methods.
60
![Page 61: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/61.jpg)
An Example
61
public void testEquals() {
Complex c1 = new Complex();
Complex c2 = new Complex(2.0, 3.0);
Complex c3 = new Complex(0.0, 0.0);
assertFalse(c1.equals(c2));
assertTrue(c1.equals(c3));
}
![Page 62: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/62.jpg)
An Example
62
public void testAdd() {
Complex c1 = new Complex(2.0, 3.0);
Complex c2 = new Complex(1.0, 1.0);
c3 = c1.add(c2);
assertEquals(3.0, c3.getRe());
assertEquals(4.0, c3.getIm());
}
![Page 63: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/63.jpg)
An Example
63
public void testAdd() {
Complex c1, c2, c3, c4;
c1 = new Complex(2.0, 3.0);
c2 = new Complex(1.0, 1.0);
c3 = c1.add(c2);
c4 = new Complex(3.0, 4.0);
assertTrue(c4.equals(c3));
}
![Page 64: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/64.jpg)
An Example
64
public void testSub() {
Complex c1, c2, c3;
c1 = new Complex(2.0, 3.0);
c2 = new Complex(1.0, 1.0);
c3 = c1.sub(c2);
assertEquals(1.0, c3.getRe());
assertEquals(2.0, c3.getIm());
}
![Page 65: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/65.jpg)
An Example
65
public void testSub() {
Complex c1, c2, c3, c4;
c1 = new Complex(2.0, 3.0);
c2 = new Complex(1.0, 1.0);
c3 = c1.sub(c2);
c4 = new Complex(1.0, 2.0);
assertTrue(c4.equals(c3));
}
![Page 66: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/66.jpg)
An Example
66
public void testMul() {
Complex c1, c2, c3;
c1 = new Complex(2.0, 3.0);
c2 = new Complex(1.0, 1.0);
c3 = c1.mul(c2);
assertEquals(-1.0, c3.getRe());
assertEquals(5.0, c3.getIm());
}
![Page 67: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/67.jpg)
An Example
67
public void testMul() {
Complex c1, c2, c3, c4;
c1 = new Complex(2.0, 3.0);
c2 = new Complex(1.0, 1.0);
c3 = c1.mul(c2);
c4 = new Complex(-1.0, 5.0);
assertTrue(c4.equals(c3));
}
![Page 68: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/68.jpg)
An Example
68
public void testDiv() {
Complex c1, c2, c3;
c1 = new Complex(2.0, 3.0);
c2 = new Complex(1.0, 1.0);
try {
c3 = c1.div(c2);
assertEquals(2.5, c3.getRe());
assertEquals(0.5, c3.getIm());
} catch (DivByZeroException e) {
assertTrue(“No exception should be thrown.”,
false);
}
![Page 69: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/69.jpg)
An Example
69
c2 = new Complex();
try {
c3 = c1.div(c2);
assertFalse(“An exception should be thrown.”,
true);
} catch (DivByZeroException e) {
assertFalse(false);
}
}
![Page 70: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/70.jpg)
An Example
70
public void testDiv() {
Complex c1, c2, c3;
c1 = new Complex(2.0, 3.0);
c2 = new Complex(1.0, 1.0);
try {
c3 = c1.div(c2);
c4 = new Complex(2.5, 0.5);
assertTrue(c4.equals(c3));
} catch (DivByZeroException e) {
assertTrue(“No exception should be thrown.”,
false);
}
![Page 71: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/71.jpg)
An Example
71
c2 = new Complex();
try {
c3 = c1.div(c2);
assertFalse(“An exception should be thrown.”,
true);
} catch (DivByZeroException e) {
assertFalse(false);
}
}
![Page 72: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/72.jpg)
An Example
72
public void testToString() {
Complex c1, c2;
c1 = new Complex();
assertEquals(“0.0+0.0i”, c1.toString());
c2 = new Complex(1.0, 1.0);
assertEquals(“1.0+1.0i”, c2.toString());
}
![Page 73: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/73.jpg)
SetUp Method (Refactoring)
73
protected void setUp() { /* Initialize common objects
c1 = new Complex(2.0, 3.0);
c2 = new Complex(1.0, 1.0);
}
public void testAdd() {
Complex c3;
setUp();
c3 = c1.add(c2);
assertEquals(new Complex(3.0, 4.0), c3);
}
![Page 74: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/74.jpg)
SetUp Method
74
class ComplexTest extends TestCase {
private Complex c1, c2;
public void testComplex() { … }
public void testEquals() { … }
public void testAdd() { … }
public void testSub() { … }
public void testMul() { … }
public void testDiv() { … }
public void testToString() { … }
protected void setUp() { … }
…
}
![Page 75: Introduction to JUnit - ecourse2.ccu.edu.tw](https://reader030.fdocuments.in/reader030/viewer/2022020621/61e8139d59bf97150c33d2c1/html5/thumbnails/75.jpg)
TearDown Method
75
class ComplexTest extends TestCase {
private Complex c1, c2;
public void testComplex() { … }
public void testEquals() { … }
public void testAdd() { … }
public void testSub() { … }
public void testMul() { … }
public void testDiv() { … }
public void testToString() { … }
protected void setUp() { … }
protected void tearDown() { /* Clean up }
…
}