关于Junit
来源:互联网 发布:淘宝海外代购可信吗 编辑:程序博客网 时间:2024/05/16 11:03
JUnit简单介绍
- JUnit是什么
JUnit是xUnit的一个子集,xUnit是一套基于测试驱动开发的测试框架,除了用来测试Java程序的JUnit,xUnit还包含PythonUnit和CppUnit等测试框架. - JUnit怎么用
- JUnit API介绍
常用:
断言assertEquals(expected,actual)判断实际输出与预测输出是否相等 - JUnit 代码框架
- JUnit API介绍
import org.junit.*;public class TestFoobar { @BeforeClass public static void setUpClass() throws Exception { // Code executed before the first test method } @Before public void setUp() throws Exception { // Code executed before each test } @Test public void testOneThing() { // Code that tests one thing } @Test public void testAnotherThing() { // Code that tests another thing } @Test public void testSomethingElse() { // Code that tests something else } @After public void tearDown() throws Exception { // Code executed after each test } @AfterClass public static void tearDownClass() throws Exception { // Code executed after the last test method }}
- 常见问题
问题:private,protect函数的测试
解决:使用Java反射的getDeclaredMethod()函数
例子:
private String emotion(String content,String scName){ //私聊 if(content.contains("//Greet")){ return("Nice to meet you,"+scName+"."); }else{ return("There is no perset emotion for your words."); }}@Testpublic void testemotiom() throws Exception { ChatServer cs = new ChatServer(); Object a=null; try{ Method method = cs.getClass().getDeclaredMethod("emotion",new Class[] {String.class, String.class}); method.setAccessible(true); //让其方法可访问 a = method.invoke(cs, new Object[] {"//Greet", "liqi"}); }catch(Exception ex){} assertEquals("Nice to meet you,liqi.",a.toString());}
问题:mock final method
解决:Mockito不支持,JMock,PowerMock,PreMock支持
their real behavior is executed without any exception. Mockito cannot warn you about mocking final methods so be vigilant.
0 0
- 关于junit
- 关于Junit
- 关于junit的疑问
- 关于junit不支持多线程?
- 关于junit断言
- 关于JUnit 的笔记
- 关于Junit测试框架
- 关于junit生成单元测报
- 关于Junit注释的说明
- 关于Junit不能运行问题
- 关于Android Junit test 配置
- 关于一个junit的例子的分析
- JUnit关于数据库访问的单元测试 (2)
- JUnit关于数据库访问的单元测试 (fi)
- 关于Eclipse插件的JUnit测试。
- 关于JUNIT的多线程测试问题
- 关于测试框架junit dbunit strutstestcase
- Junit 使用中,关于SessionFactory的建立
- BaseAdapter方法介绍isEnabled、getViewTypeCount、getItemViewType
- TextView:文本视图。
- DES加密解密算法基础
- php连接mysql
- java中的clone()方法的研究---(5)如何编写正确的clone()方法:String类型
- 关于Junit
- WAJUEJI which home strong!
- Ubuntu 12.04LTS Openwrt 入门准备
- Linux的信息查看命令
- Generic Programming and the STL笔记7--容器类
- 准备好这些 高考考场也会很轻松
- 专业的PDF文档转换控件
- 【memcache】的基本命令
- 自定义AlertDialog(仿微信)