发表于: 2017-08-03 21:12:11

2 1076


今天完成:


testSum=10



junit注解DEMO

import java.util.ArrayList;
import org.junit.*;
import static  org.junit.Assert.*;

public class AnnotationsTest {
private ArrayList testList;

@BeforeClass
   public static void onceExecuteBeforeAll(){
System.out.println("@BeforeClass:onceExecuteBeforeAll");
}

@Before
   public void executedBeforeEach(){
testList = new ArrayList();
System.out.println("@Before:executedBeforeEach");
}

@AfterClass
   public static void onceExecutedAfterAll(){
System.out.println("@AfterClass:onceExcutedAfterAll");
}

@After
   public void executedAfterEach(){
testList.clear();
System.out.println("@After:executeAfterEach");
}

@Test
   public void EmptyCollection(){
assertTrue(testList.isEmpty());
System.out.println("@Test:EmptyCollection");
}

@Test
   public void OneItemCollection(){
testList.add("oneItem");
assertEquals(1,testList.size());
System.out.println("@Test:OneItemArrayList");
}

@Ignore
   public void executionIgnored(){
System.out.println("@Ignore:This execution is ignored");
}
}


明日计划:

学习Junit断言


遇到的问题:



收获:

Junit注解:

@Test(public void method())  测试注释指示该公共无效方法它所附着可以作为一个测试用例

@Before(public void method()) 该方法必须在类中的每个测试之前执行,以便满足执行测试的必要先决条件

@BeforeClass(public static void method()) 这是附着在静态方法必须执行一次并在类的所有测试之前

                                                                       一般用于测试计算共享配置方法(如:连接到数据库

@After(public void method()) After注释指示,该方法在执行每项测试后执行(如执行每个测试后重置某些变量,删除临时变量

@AfterClass(public static void method())  当需要的执行的所有测试在Junit测试用例类后执行,可用AfterClass清理建立方法,如从数据库断开连接  附有此批注的方法必须定义为静态

@Ignore(public static void method()) 当想暂时禁用特定的测试执行可以使用忽略注释 每个被注解为@Ignore的方法将不被执行





返回列表 返回列表
评论

    分享到