Java之Junit4单元测试

每编写完一个函数之后,都应该对这个函数的方方面面进行测试,这样的测试我们称之为单元测试,传统的编程方式,我们要重新写另外一个程序,在该程序中调用我们需要测试的方法,当我们需要测试的方法过多时,就显得很鸡肋了....



在所在需要测试函数上@Test,就可以进行测试了(引org.junit包后就可以使用)


package com.java.jdbc;

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

public class TestJunit {
	
	@Before
	public void testBefore(){
		System.out.println("hello ,Junit");
	}
	
	@Test
	public void testA(){
		System.out.println("A is ok");
	}
	
	@Test
	public void testB(){
		System.out.println("B is ok");
	}
	
	@After
	public void testC(){
		System.out.println(4/0);
	}
}


猜你喜欢

转载自blog.csdn.net/mmake1994/article/details/80976251