简单的例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class TestPractice extends AndroidTestCase {
//测试前进行的工作
@Override
protected void setUp() throws Exception {
super.setUp();
}

//所有测试的类必须以test开头
public void testThatDemonstratesAssertations() throws Throwable{
int a=5;
int b=3;
int c=5;
int d=10;

assertEquals("X should be equal",a,c);
assertTrue("Y should be true",d>a);
assertFalse("Z should be false",a==b);

}

//测试之后进行的工作
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
}

然后点击run 'Tests in ...即可.