JUnit4测试代码示例

JUnit4 与以前版本相比,有了很大的改变。 JUnit4 开始使用自定义的一些标签 (Annotation) 来实现测试活动。而且增加了一些功能,使用起来更加方便了。下面的测试代码能够看出不少 JUnit4 版本的一些新的东西。具体更加详细的,可以到 www.junit.org 看看。

public class JUnitFourVersionTest {

@BeforeClass

public static void setUpBeforeClass() throws Exception {

System.out.println("setUpBeforeClass()");

}

@AfterClass

public static void tearDownAfterClass() throws Exception {

System.out.println("tearDownAfterClass()");

}

@Before

public void setUp() throws Exception {

System.out.println("setUp()");

}

@After

public void tearDown() throws Exception {

System.out.println("tearDown()");

}

@Test

public void helloOne() {

System.out.println("helloOne()");

Assert.assertEquals(2, 2);

}

@Test

public void helloTwo() {

System.out.println("helloTwo()");

}

public void helloThree() {

System.out.println("helloThree()");

}

@Test

@Ignore

public void helloFour() {

System.out.println("helloFour()");

}

@Test(timeout = 1000)

public void squareRoot() {

for (;;)

;

}

@Test(expected = IllegalArgumentException.class)

public void divideByZero() {

Calculation calculation = new Calculation();

calculation.div(5, 0);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值