Java code snippets _ 3

Source: Internet
Author: User

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 ");
}
 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.