junit测试
来源:互联网 发布:fd抓包更改数据犯法么 编辑:程序博客网 时间:2024/05/16 19:27
junit测试,可以单独测试,不需要反复注释代码。
package test;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class Demo2 {
//在有多个test的时候,可以再beforewClass和before中初始和销毁(after)
//需要的变量,不需要反复编写
//beforeClass和before的区别,前者是在整个类的前后执行一次。
// before是在每个test的前后都要执行一遍。
@BeforeClass
public static void beforeClass(){ //beforeClass 的类需要是静态类。
System.out.println("初始化");
}
@Before
public void before(){
System.out.println("初始化");
}
@Test
public void run(){
Person p = new Person();
Object buid = null; //在junit3中assert是junit.framework类中的。在junit4中为下面
p.run(); //assert是import org.junit.Assert;中的
Assert.assertArrayEquals(new int[]{1,1}, new int[]{1,1}); //前者为预期值,后者世界收到的值
Assert.assertEquals("2", "1"); //多种类型,可以进行数组及各种类型的设置
Assert.assertNotNull("buid不能为空",buid); //如果变量为空,则抛出message
}
@Test
public void eat(){
Person p = new Person();
p.eat();
}
@After
public void after(){
System.out.println("销毁");
}
@AfterClass
public static void afterClass(){
System.out.println("销毁");
}
}
0 0
- junit测试
- JUnit测试
- Junit测试
- 测试 Junit
- junit测试
- Junit测试
- Junit测试
- Junit测试
- junit 测试
- Junit测试
- Junit测试
- Junit测试
- junit测试
- junit 测试
- JUnit测试
- Junit测试
- Junit测试
- Junit测试
- 筛选法产生素数表
- 屏蔽NSLog语句
- Ubuntu 服务配置(sysv-rc-conf)
- 单链表基础操作C++实现
- shell编程四~数学运算
- junit测试
- verilog语言RS232串口接收模块设计——串口调试工具发送数据在数码管显示
- 分享我的大型Java多用户商城系统开发的心得和困难
- java EE 应用(1)
- android 滑动动画效果
- 在Word2013中插入公式自动编号
- 网络协议 二
- tableViewCell小结
- 如此雾霾,何不SOHO