Package javaee. china. cxp;
Import junit. framework. Assert;
Import org. junit. After;
Import org. junit. AfterClass;
Import org. junit. Before;
Import org. junit. BeforeClass;
Import org. junit. Test;
/**
* Java testing class
* Use junit for testing
* @ Test above the tested method
*
* @ Before and @ After (@ Before is called Before each @ Test method is initialized. @ After is called After each @ Test method is completed)
* @ BeforeClass and @ AfterClass (@ BeforeClass class loading call @ AfterClass class after the class ends, each class @ BeforeClass and @ AfterClass are called only once)
* Assert. assertEquals (estimated result value of the method, method );
*/
Public class Demo_3_Junit {
Private Persion p;
@ BeforeClass
Public static void beforeClass (){
System. out. println ("beforeClass ");
}
@ Before
Public void before (){
P = new Persion ();
}
@ Test
Public void testRun (){
Persion p1 = new Persion ();
P1.run ();
}
@ Test
Public void testEat (){
Persion p2 = new Persion ();
P2.eat ();
}
@ Test
Public void testEatTwo (){
P. eat ();
}
@ After
Public void after (){
System. out. println ("after ");
}
@ Test
Public void sleep (){
Assert. assertEquals ("asleep", p. sleep ());
}
@ AfterClass
Public static void afterClass (){
System. out. println ("afterClass ");
}
}