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>,里面有一个例子挺有感触地,写出来和大家分享一下: [问题] 从输入对话框中读取三个整数值,这三个整数值代表 ...
随机推荐
- USACO Section 2.1: Hamming Codes
挺简单的一道题 /* ID: yingzho1 LANG: C++ TASK: hamming */ #include <iostream> #include <fstream> ...
- 操刀 requirejs,自己动手写一个
前沿 写在文章的最前面 这篇文章讲的是,我怎么去写一个 requirejs . 去 github 上fork一下,顺便star~ requirejs,众所周知,是一个非常出名的js模块化工具,可以让你 ...
- Struts标签、Ognl表达式、el表达式、jstl标签库这四者之间的关系和各自作用
我之前虽然会用,但是一直分不清彼此之间有什么区别,所以查找资料,将它们进行整合区分,加深了解, 一 介绍 1.Struts2的作用 Struts2标签库提供了主题.模板支持,极大地简化了视图页面的 ...
- 《自己动手写操作系统》pmtest2笔记
;DispReturn模拟一个回车的显示,(让下一个要显示的字符在下一行的开头处显示),其中edi始终指向要显示的下一个字符的位置.; ------------------------------ ...
- PHP后台执行
php中实现后台执行的方法: ignore_user_abort(true); // 后台运行set_time_limit(0); // 取消脚本运行时间的超时上限后台运行的后面还要,set_time ...
- Java 图片转换为字符图 CharMaps (整理)
/* * Java 图片转换成字符图 CharMaps (整理) * * 2016-1-2 深圳 南山平山村 曾剑锋 * * @(#)CharMaps.java 2014/1/16 * 1.这个一 ...
- css3用AnimationEnd判断动画是否完成, css3在动画完成后执行事件
用css3的animation完成一个动画,当只有这个动画完成时才执行令一个事件,比如让动画保持在终止的状态或其他一些事件.我们该怎么办呢. 第一种方法: 用计时器,设定一个和动画时长一样的time, ...
- 20160207.CCPP体系详解(0017天)
程序片段:01.Point.c+02.进程.c+03.内存的栈和堆.c 内容概要:内存32位和64位的区别 ///01.Point.c #include <stdio.h> #includ ...
- NHibernate实例化类部分属性
NHibernate 为习惯SQL的开发者提供了接口,将查询的结果转变为持久化对象.虽然该方法不是很提倡. GetCurrentSession().CreateSQLQuery(sql) 参数sql就 ...
- Java中Volatile关键字详解
一.基本概念 先补充一下概念:Java并发中的可见性与原子性 可见性: 可见性是一种复杂的属性,因为可见性中的错误总是会违背我们的直觉.通常,我们无法确保执行读操作的线程能适时地看到其他线程写入的值, ...