JUnit测试框架
2013-05-15 18:01
369 查看
------- android培训、java培训、期待与您交流!
----------
JUnit是由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架(regression testing framework)。Junit测试是程序员测试,即所谓白盒测试,因为程序员知道被测试的软件如何(How)完成功能和完成什么样(What)的功能。Junit是一套框架,继承TestCase类,就可以用Junit进行自动测试了。
@Test 测试功能的方法
@Before 关联资源和创建资源的方法
@After 关闭和释放资源的方法
@Before和@After方法在 每一个Test运行时,@Before先运行和@After后运行
@BeforeClass
和Befoer相类似,不过是静态,类加载时即运行
@AfterClass和After相类似,不过也是静态的,类释放时同时运行。
断言:Assert类(用于判断实际值是否是期望值,在JUnit小窗口显示)
static Assert.assertXXX(experctrd,actual)
actual通常是调用某个方法的返回值与expected来进行比较。
----------
JUnit是由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架(regression testing framework)。Junit测试是程序员测试,即所谓白盒测试,因为程序员知道被测试的软件如何(How)完成功能和完成什么样(What)的功能。Junit是一套框架,继承TestCase类,就可以用Junit进行自动测试了。
public class Person { public void eat() { System.out.println("eat"); } public void run() { System.out.println("run"); } }
@Test 测试功能的方法
@Before 关联资源和创建资源的方法
@After 关闭和释放资源的方法
@Before和@After方法在 每一个Test运行时,@Before先运行和@After后运行
public class Demo0 { Person p =null; @Before public void Before()//创建资源 { p = new Person(); System.out.println("new Person"); } //测试功能 @Test public void testEat() { p.eat(); } @Test public void testRun() { p.run(); } //释放资源 @After public void After() { p = null; System.out.println("p=null"); } }
@BeforeClass
和Befoer相类似,不过是静态,类加载时即运行
@AfterClass和After相类似,不过也是静态的,类释放时同时运行。
public class Demo01 { static Person p =null; @BeforeClass public static void Before()//创建资源 { p = new Person(); System.out.println("new Person"); } //测试功能 @Test public void testEat() { p.eat(); } @Test public void testRun() { p.run(); } //释放资源 @AfterClass public static void After() { p = null; System.out.println("p=null"); } }
断言:Assert类(用于判断实际值是否是期望值,在JUnit小窗口显示)
static Assert.assertXXX(experctrd,actual)
actual通常是调用某个方法的返回值与expected来进行比较。
相关文章推荐
- 黑马程序员----JAVA基础之junit测试框架
- Android Studio中使用junit4测试框架中的坑
- 深入理解JUnit测试框架 --- JUnit使用、命名规范、相关注解
- JavaWeb学习笔记-java基础-1-测试框架junit
- Junit框架使用(6)-- 测试套件与Maven测试
- JUnit测试框架使用介绍 推荐
- 实践作业3:白盒测试----学习Junit框架DAY10.
- android基础知识12:android自动化测试03—基于junit的android测试框架03
- Java-测试框架之JUnit3和JUnit4使用区别的总结
- junit测试框架
- Java测试框架TestNG和JUnit对比
- Junit测试框架
- 用JUnit测试Spring管理Hibernate框架的一个例子
- Maven整合Junit unitils测试框架 cannot retrieve JUnit method
- Junit测试框架初探
- JUnit中使用Hamcrest测试框架的assertThat断言【4.4新特性】
- 【测试学习】(一)——JUnit测试框架和组合模式
- Android中使用Junit测试框架
- android自动化测试03—基于junit的android测试框架
- Dbunit(基于junit扩展的数据库测试框架。)vs Jmockit