package code; public class MyCode { public int m1(){
System.out.println("数字型");
return 1;
} public String m2(){
System.out.println("null");
return null;
} public boolean m3(){
System.out.println("boolean");
return true;
}
//------------------------------------------
static MyCode obj = new MyCode();
public MyCode m4_1(){
System.out.println("obj");
return obj;
} public MyCode m4_2(){
System.out.println("obj");
return obj;
}
}
package test; import code.MyCode;
import junit.framework.TestCase; public class TestJunit extends TestCase { public void testM1() {
MyCode mc = new MyCode();
assertEquals(1, mc.m1());
} public void testM2() {
MyCode mc = new MyCode();
assertNull(mc.m2());
} public void testM3() {
MyCode mc = new MyCode();
assertTrue(mc.m3());
} public void testM4() {
MyCode mc = new MyCode();
assertSame(mc.m4_1(), mc.m4_2());
} public static void main(String[] args) {
/*
* 由此 Class 对象建模的类的类型。例如,String.class 的类型是 Class<String>。
*/
junit.textui.TestRunner.run(TestJunit.class);
} }