【メモ】Eclipse and Java for Total Beginners-005
6094 ワード
Lesson 05 – JUnit Testing Continued Test Person class – part 2 Create test methods for constructor, getName, and getMaximumBooks Static methods
ここのassertEqualsはStatic methodです.所属するClassの内部にある場合は、Classと略記します.
ここのassertEqualsはStatic methodです.所属するClassの内部にある場合は、Classと略記します.
1
package
org.totalbeginner.tutorial;
2
3
import
org.totoalbeginner.tutorial.Person;
4
5
import
junit.framework.TestCase;
6
7
public
class
PersonTest
extends
TestCase {
8
9
public
void
testPerson() {
10
Person p1
=
new
Person();
11
assertEquals(
"
unknown name
"
, p1.getName());
12
assertEquals(
3
, p1.getMaximumBooks());
13
}
14
15
public
void
testSetName() {
16
Person p2
=
new
Person();
17
p2.setName(
"
Fred
"
);
18
assertEquals(
"
Fred
"
, p2.getName());
19
}
20
21
public
void
testSetMaximumBooks() {
22
Person p3
=
new
Person();
23
p3.setMaximumBooks(
10
);
24
assertEquals(
10
, p3.getMaximumBooks());
25
}
26
27
}