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>,里面有一个例子挺有感触地,写出来和大家分享一下: [问题] 从输入对话框中读取三个整数值,这三个整数值代表 ...
随机推荐
- 转载 a href=#与 a href=javascript:void(0) 的区别
a href="#"> 点击链接后,页面会向上滚到页首,# 默认锚点为 #TOP <a href="javascript:void(0)" onCl ...
- 【公司要求】- RPC学习(一)
HADOOP-IPC(这里说的是1.0.4版本) 是轻量级RPC,在hadoop中主要用于2方面 1.TaskTracker和JobTracker 通讯. 2.NameNode和DataNode通讯. ...
- flex 4 布局样式
Flex 4 样式与布局 第一篇 Flex 4 与自定义布局(Layout) Flex 4/Spark组件架构的新功能之一是可以定制一个容器的布局而不必改变容器本身.您需要做的就是定义一个自定义布局. ...
- MAVEN “Plugin execution not covered by lifecycle configuration”
pom文件中报错提示: Plugin execution not covered by lifecycle configuration: net.alchim31.maven:yuicompresso ...
- Spring 实践 -IoC
Spring 实践 标签: Java与设计模式 Spring简介 Spring是分层的JavaSE/EE Full-Stack轻量级开源框架.以IoC(Inverse of Control 控制反转) ...
- POJ 2528 (线段树 离散化) Mayor's posters
离散化其实就是把所有端点放在一起,然后排序去个重就好了. 比如说去重以后的端点个数为m,那这m个点就构成m-1个小区间.然后给这m-1个小区间编号1~m-1,再用线段树来做就行了. 具体思路是,从最后 ...
- Uva 10382 (区间覆盖) Watering Grass
和 Uva 10020几乎是一样的,不过这里要把圆形区域转化为能够覆盖的长条形区域(一个小小的勾股定理) 学习一下别人的代码,练习使用STL的vector容器 这里有个小技巧,用一个微小量EPS来弥补 ...
- 漫游Kafka实战篇之搭建Kafka运行环境
接下来一步一步搭建Kafka运行环境. Step 1: 下载Kafka 点击下载最新的版本并解压. > tar -xzf kafka_2.9.2-0.8.1.1.tgz > cd kafk ...
- decorate装饰模式
package com.decorate; public class Iphone implements Phone{ @Override public void call() { System.ou ...
- IOS中用UIFont返回字体的行高、动态改变tableView中Cell的高度
一.动态改变Cell的高度 1.利用tableView代理方法的返回值决定每一行cell的高度 - (CGFloat)tableView:(UITableView *)tableView height ...