First step of using junit---------Software Testing Lab 1---2016.03.18
1. Install junit
a) Download “junit.jar”
b) In eclipse, Windows->Preferences->Java->Build Path->Classpath variables->New,
add "junit.jar" file.
2. Install hamcrest
a) Download “hamcrest.jar”
b) In eclipse, Windows->Preferences->Java->Build Path->Classpath variables->New,
add the downloaded jar file.
3. Install eclemma
a) In eclipse, Help->Eclipse Marketplace, find eclemma in the market and install it
4. Build a new project
a) Build a new project named “TestingLab1”
b) Create a new class under “src” to write our source code---TestingLab1/src/cn/tju/st/Cal.java
c) Create a new folder under this project to write the testing code---TestingLab1/test/cn/tju.st/test/Testing.java
d) Import “junit.jar” and “hamrcrest” to the project.
i. Click the right mouse button at the project and select “Propertise”.
ii. Propertise->Java Build Path->Add Variables
iii. Select “junit” and “hamrcrest”and click “OK”
5. Write the source code in Cal.java
package cn.tju.st;
public class Cal{
//calculate the triangle's type
public int triangle(int a, int b, int c){
if(a == b || b ==c || c == a){
if(a == b)
return 0; //equilateral
else
return 1; //isosceles
}
return 2; //scalene
}
}
6. Write the test code in Testing.java
a) Use org.junit.Assert.assertEquals to test the source code with an expected result.
b) Write “@Test” before the test function
package cn.tju.st.test; import cn.tju.st.Cal;
import org.junit.*;
import static org.junit.Assert.*; public class Testing{
@Test
public void testEquilateral(){
assertEquals(0, new Cal().triangle(2, 2, 2));
} @Test
public void testIsosceles(){
assertEquals(1, new Cal().triangle(1, 2, 2));
assertEquals(1, new Cal().triangle(2, 1, 2));
} @Test
public void testScalene(){
assertEquals(2, new Cal().triangle(2, 3, 4));
}
}
7. Testing the source
a) Click the right mouse button at the project and select “Coverage->Junit Test”
8. Results
a) When the code is executed, it becomes green
b) When the code is not executed, it becomes red
c) When the code is executed partly, it becomes yellow
d) When we test by “testEquilateral()”,
@Test
public void testEquilateral(){
assertEquals(0, new Cal().triangle(2, 2, 2));
}
In "Cal.java"
i) the first“if” just execute “a==b”, it becomes yellow.
j) the second “if” execute “a==b” and then “return ture”, but it doesn’t execute the other case(a !=b), it becomes yellow. If and only if the“if”executes all the conditions(when it’s ture and when it’s false), it becomes green.
k) the others becomes red because of no executing
l) now you can see the coverage and it is not all 100%
e) When we test by “testEquilateral()” and “testIsosceles()” at the same time,
the second “if” executes “a==b”, get the true and false with different test case, the it becomes green.
f) When we test all 3 functions, the code becomes green, because all conditions have been concerned.
and now you can see the coverage all 100%.
sourcecode link: https://github.com/xuexcy/SoftwareTestingLab1
First step of using junit---------Software Testing Lab 1---2016.03.18的更多相关文章
- Software Testing, Lab 1
1.Install Junit(4.12), Hamcrest(1.3) with Eclipse 2.Install Eclemma with Eclipse 3.Write a java prog ...
- Software Testing Techniques LAB 02: Selenium
1. Installing 1. Install firefox 38.5.1 2. Install SeleniumIDE After installing, I set the view o ...
- FW:Software Testing
Software Testing Testing with a Purpose Software testing is performed to verify that the completed s ...
- 101+ Manual and Automation Software Testing Interview Questions and Answers
101+ Manual and Automation Software Testing Interview Questions and Answers http://www.softwaretesti ...
- Exploratory Software Testing
最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...
- 软件测试software testing summarize
软件测试(英语:software testing),描述一种用来促进鉴定软件的正确性.完整性.安全性和质量的过程.软件测试的经典定义是:在规定的条件下对程序进行操作,以发现程序错误,衡量软件质量,并对 ...
- 读书笔记-Software Testing(By Ron Patton)
Software Testing Part I:The Big Picture 1.Software Testing Background Bug's formal definition 1.The ...
- software testing
Software Testing Software testing is the process of evaluation a software item to detect differences ...
- 探索式软件测试—Exploratory Software Testing
最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...
- 《The art of software testing》的一个例子
这几天一直在看一本书,<The art of software testing>,里面有一个例子挺有感触地,写出来和大家分享一下: [问题] 从输入对话框中读取三个整数值,这三个整数值代表 ...
随机推荐
- Linux命令-free
显示系统内存使用情况 free [-m / -g / -h] [root@localhost test]# free -m total used free shared buff/cache ava ...
- RMI、Hessian、Burlap、Httpinvoker、WebService的比较
RMI.Hessian.Burlap.Httpinvoker.WebService的比较 2(转) [2]Java远程调用方法性能比较 [IT168技术]现在,Java远程调用方法很多,各种方 ...
- 机器人学 —— 机器人视觉(Bundle Adjustment)
今天完成了机器人视觉的所有课程以及作业,确实是受益匪浅啊! 最后一个话题是Bundle Adjustment. 机器人视觉学中,最顶尖的方法. 1.基于非线性优化的相机位姿估计 之前已经在拟合一篇中, ...
- Linux下安装mysql-5.6.4 的图文教程
在开始安装前,先说明一下mysql-5.6.4与较低的版本在安装上的区别,从mysql-5.5起,mysql源码安装开始使用cmake了,因此当我们配置安装目录./configure --perfix ...
- 浅谈学习C++时用到的【封装继承多态】三个概念
封装继承多态这三个概念不是C++特有的,而是所有OOP具有的特性. 由于C++语言支持这三个特性,所以学习C++时不可避免的要理解这些概念. 而在大部分C++教材中这些概念是作为铺垫,接下来就花大部分 ...
- Python学习之类
class Person: def __init__(self, name): self.name = name def sayHi(self): print('Hello, my name is'+ ...
- c#开源Excel操作库--NPOI
前言 以前也用C#操作过excel,用的是OleDb或者offic的com组件,但是总是非常的麻烦,依赖限制较多,所以果断寻找开源方案,JAVA上面已经有非常成熟的POI,就这样,找到了移.Net的移 ...
- C#多态;父类引用指向子类对象;new和override的区别;new、abstract、virtual、override,sealed关键字区别和使用代码示例;c#类的初始化顺序
关于父类引用指向子类对象 例如: 有以下2个类 public class Father { public int age = 70; public static string name = " ...
- HDU 3666 THE MATRIX PROBLEM (差分约束,最短路)
题意: 给一个n*m矩阵,每个格子上有一个数字a[i][j],给定L和U,问:是否有这样两个序列{a1...an}和{b1...bn},满足 L<=a[i][j]*ai/bj<=U .若存 ...
- 在Datatables中加入错误提示功能
经常用Datatables的童鞋一定碰到过当采用服务端请求的时候,一旦后台出现异常,Datatables的会一直卡在那里,中间的正在处理的提示一直停留着. 为了能给用户更好的体验,需要对Datatab ...