Junit的annotation(注释、注解)

来源:互联网 发布:mac设置桌面图标 编辑:程序博客网 时间:2024/05/29 23:45

package com.jimmy.test;

import static org.junit.Assert.*;import static org.hamcrest.Matchers.*;

import org.junit.AfterClass;import org.junit.Before;import org.junit.After;import org.junit.BeforeClass;import org.junit.Test;

import com.jimmy.T;

public class TTest { @BeforeClass public static void beforeclass(){  System.out.println("beforeclass"); }  @Before public void before(){  System.out.println("before"); }  @Test public void testAdd() {  int z=new T().add(5,5);  assertThat(z, is(10));   }  @Test(expected=java.lang.ArithmeticException.class) public void testDivide(){  int z=new T().divide(8, 0);  assertThat(z,is(2)); }  @After public void after(){  System.out.println("after"); }  @AfterClass public static void afterclass(){  System.out.println("afterclass"); }}


用@Test 表名方法是测试方法,expected表示该方法抛出异常,timeout表示该方法要在几秒内完成才算成功

@Ignore 忽略该方法,不进行测试

@before 每个测试方法执行前执行

@after 每个测试方法执行后执行

@BeforeClass 所有测试运行之前(测试类运行之前) 执行

@AfterClass 所有测试运行之前(测试类运行之前) 执行

 

原创粉丝点击