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>,里面有一个例子挺有感触地,写出来和大家分享一下: [问题] 从输入对话框中读取三个整数值,这三个整数值代表 ...
随机推荐
- iOS:核心动画的详解介绍:CAAnimation(抽象类)及其子类
核心动画的详解介绍:CAAnimation(抽象类) 1.核心动画基本概念 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍! 使用它 ...
- .NET 压缩解压库发布,支持进度查看
刚发布了一个 .net压缩解压库,基于SharpZipLib开发 ,支持进度查看,支持路径保持与否. CL.IO.Zip 是一个基于SharpZipLib的一个压缩和解压的类库,提供给用户在.net环 ...
- mysql union和union all
UNION 操作符用于合并两个或多个 SELECT 语句的结果集.UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型. union 是对数据进行并集操作,不包括重复 ...
- android学习系列:jercy——AI3 的博客
[android学习之十七]——特色功能2:桌面组件(快捷方式,实时文件夹) 二.桌面组件 1.快捷方式 Android手机上得快捷方式的意思可以以我们实际PC机器上程序的快捷方式来理解.而andro ...
- Android之开发杂记(二)
1.android 4.0 以后 高版本没有虚拟菜单键
- objective-c 与 js之间传递中文乱码
最近在做关于js改写oc framework的小project,遇到了不少问题 其中刚遇到的是关于如何在两者之间传递中文字符,带特殊字符的URL字符串 不会很详细的介绍太多,以后会回头做个总结 oc传 ...
- Android:将View的内容映射成Bitmap转图片导出
前段时间在网上看到这么个例子是将view映射到一个bitmap中,稍加改进可以用于一些截图工具或者截图软件(QQ截图之类),例子写的不够完善,不过很有些学习的意义内容大致如下: 在Android中自有 ...
- && 用法解释
A&&B 首先判断A,A成功然后判断B:A不成功则结束判断.
- 【MySQL】ERROR 1045 (28000): Access denied for user的解决方法
去官网下载压缩版的MySQL Server,解压配置path环境变量后.然后克隆my-default.ini创建my.ini文件,在文件中[mysqld]下面配置basedir和datadir bas ...
- CSS3与页面布局学习总结(三)——BFC、定位、浮动、垂直居中
一.BFC与IFC 1.1.BFC与IFC概要 BFC(Block Formatting Context)即“块级格式化上下文”, IFC(Inline Formatting Context)即行内格 ...