Junit4单元测试(2)

来源:互联网 发布:软件注册权登记 编辑:程序博客网 时间:2024/06/06 04:12
package test;import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Ignore;import org.junit.Test;import com.foo.www.*;/** *  测试类 * @author  * */public class TestMyMath {//必须加static@BeforeClasspublic static void startTestMyMath(){System.out.println("初始化测试类。。。");System.out.println("例如:建立数据库的链接。。。");}@Testpublic void  testAdd(){MyMath mymath=new MyMath();mymath.add(2,3);org.junit.Assert.assertEquals(5, 5);}@Ignorepublic void IgnoreMethod(int x,int y){//此方法运行该测试类时候被忽略,不执行。}//必须加static@AfterClasspublic static void endTestMyMath(){System.out.println("释放资源。。。");System.out.println("测试类运行结束。。。");}}

运行多个测试用例

项目右键------>>>>>>>>run Configurations------->>>>>>JUnit  ------>>>>选择Run all tests in.....选择一个包运行。

0 0