Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2161013
  • 博文数量: 556
  • 博客积分: 11457
  • 博客等级: 上将
  • 技术积分: 5973
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-24 22:33
文章分类

全部博文(556)

文章存档

2013年(22)

2012年(74)

2011年(460)

分类: Java

2012-03-10 22:44:13


点击(此处)折叠或打开

  1. package com.bird.junit;

  2. import junit.framework.Assert;

  3. import org.junit.After;
  4. import org.junit.Before;
  5. import org.junit.Test;

  6. public class TestPerson {
  7.     private Person p;
  8.     @Before
  9.     public void before(){
  10.         p=new Person();
  11.         System.out.println("Before");
  12.     }
  13.     @Test
  14.     public void testRun(){
  15.         //断言

  16.         Assert.assertEquals("2",p.run());
  17.     }
  18.     @Test
  19.     public void testEat(){
  20.         //断言

  21.         p.eat();
  22.     }
  23.     
  24.     @After
  25.     public void after(){
  26.         p=null;
  27.         System.out.println("After");
  28.     }
  29. }
其中Before标签是让其他方法运行前进行运行,after 的意思大家都懂得,那个 Assert断言的功能更加的简单,就是在测试的时候确认返回值是否符合大家的期望,可见测试还是很简单的。
阅读(2712) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~