`
yidongkaifa
  • 浏览: 4060150 次
文章分类
社区版块
存档分类
最新评论

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

}

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics