今天是软件测试的上机,主要内容是对junit的安装以及对一个简单类的测试实践。老师推荐用eclipse,但是我原来一直在

用intellj Idea,所以我试了试intellj Idea对junit的安装使用。下面介绍过程。

安装:

  intellj Idea 自带了junit模块,所以安装起来很简单。

  首先,打开intellj Idea,双击shift键,搜索plugins,点击下图中画红线的button。

  

  进入plugins后,搜索junit,选中下面画红圈插件后面的对勾,然后确定并重启intellj Idea。

至此安装完成。

  顺带一提,大量的快捷键也是intellj Idea的魅力之一,让人感觉非常方便,开发起来很舒服。

使用:

  intellj idea 上junit的使用非常方便。首先在src平级目录中创建测试文件夹,这样可以将测试代码和被测试代码分开。我这里创建

的是test文件夹,在该文件夹上右键,点击Mark Directory as --->Test Source Root

  然后在src中创建要测试的类,选中类名,按ctrl+shift+T,点击create new test

进入测试创建界面,如下图选择箭头所指的junit4确定就创建了测试类

接下来就可以进行测试啦!

测试:

  用来进行测试的代码:

public class JunitTest {
public String plus(double a,double b,double c){
if(a+b<=c||b+c<=a||a+c<=b)return"This is not a trangle";
else
if(a==b&&a==c)return"This is an equilateral";
else
if(a==b||a==c||b==c)return "This is an isosceles";
else return "This is a scalene";
}
}

  测试代码:

import org.junit.Before;
import org.junit.Test; import static org.junit.Assert.*; /**
* Created by ltp on 2016/3/17.
*/
public class JunitTestTest {
private JunitTest junT;
@Before
public void setUp() throws Exception {
junT = new JunitTest();
}
@Test
public void testPlus() throws Exception {
assertEquals("This is not a trangle",junT.plus(22,3,4));
assertEquals("This is an equilateral",junT.plus(3,3,3));
assertEquals("This is an isosceles",junT.plus(3,3,4));
assertEquals("This is a scalene",junT.plus(5,3,4)); }
}

  点击右上的edit configurations配置运行环境

然后就可以运行测试啦!

测试结果:

这就是junit在intellj idea中得安装及使用方法。

最新文章

  1. JavaScript HTML CSS外部链接
  2. bzoj1042: [HAOI2008]硬币购物
  3. summary of k Sum problem and solutions in leetcode
  4. Servlet获得Http请求,GET/POST
  5. Dynamic Expression.Call Any
  6. Logistic Regression and Classification
  7. 使用 Java 配置进行 Spring bean 管理--转
  8. oracle触发器应用
  9. django学习之Model(五)MakingQuery
  10. R语言成功加载rJava方法
  11. no zuo no die
  12. Mysql 通用知识 2019-03-27
  13. 避免切换横竖屏Fragment的重复加载导致UI混乱
  14. .net core实践系列之短信服务-架构设计
  15. [CC-BSTRLCP]Count Binary Strings
  16. python调用 sshpass
  17. [UE4]蓝图继承方法:重写父类方法时,增加父类方法调用
  18. 面向对象 【类库】【委托】【is as运算符】
  19. 深入理解指针—&gt;结构体里的成员数组和指针
  20. [转载] 关于matlab GUI的一点心得

热门文章

  1. 开启MSSQLServer跨服务器查询功能
  2. 学习Oracle一个星期以来的总结
  3. JAVA Calendar详解(转)
  4. Sql Server数据库基础
  5. 模拟app上商品详情点击图片放大并且可以切换大图
  6. web2py官方文档翻译
  7. u Calculate e
  8. CSS自学笔记(10):CSS3盒子模型
  9. python---连接MySQL第一页
  10. Android UI ActionBar功能-在 Action Bar 上添加按钮