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系统文件访问控制列表
linux系统中的RWX权限.特殊权限.隐藏权限都是对某一类用户设置的, 而如果希望对某个指定的用户进行单独的权限设置的话就需要用到文件的 访问控制权限了. 我们可以对普通文件或目录进行设置ACL,通 ...
- lua简化cocos2dx的Action动画序列
情景 今天写代码时,又要写一个很常见的动画,就是变大变小模拟那个弹性的赶脚,很常用但写起来挺麻烦,封装一下用起来就简单多了. 当然我也知道有缓动动画(EaseAction)可以实现反弹效果,但这不是重 ...
- 如何写计算机会议的rebuttal
其实最好的教材就是实例,恰好NIPS会议会把往年所有论文的Rebuttal都贴出来...,见这里:http://papers.nips.cc/ 同时,圈内同行也总结了不少经验,下面转帖其他人的经验 = ...
- VMware VMware各版本
VMware各版本 一.VMware vSphere5: VMware vSphere5 取代原 VMware ESX 二.VMware ESXI/VMware Citrix/VMware XenS ...
- js dom
JavaScript的DOM操作 1.DOM的基本概念 DOM是文档对象模型,这种模型为树模型:文档是指标签文档:对象是指文档中每个元素:模型是指抽象化的东西. 2.Window对象操作 一.属性和方 ...
- Ubuntu下安装Git以及Git帮助手册【转】
转自:http://milkythinking.com/blog/2011/04/17/install_git_and_manual/ Git简介 Git是一个分布式版本控制系统,对应的是SVN.CV ...
- Pascal's Triangle(帕斯卡三角)
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 《OD大数据实战》Hive入门实例
官方参考文档:https://cwiki.apache.org/confluence/display/Hive/LanguageManual 一.命令行和客户端 1. 命令窗口 1)进入命令窗口 hi ...
- Balsamiq Mockups简单介绍(UI草图绘制工具)
什么是Balsamiq Mockups Balsamiq Mockups出自加利福尼亚州的Balsamiq工作室,创始人Peldi在2008年6月推出了这款手绘风格的产品原型设计工具,并广受好评.2年 ...
- 未能加载文件或程序集“XXXXXX”或它的某一个依赖项。试图加载格式不正确的程序。
在本机WIN7机器上的WebService部署到Win2008R2上发现错误 “/”应用程序中的服务器错误. 未能加载文件或程序集“XXXXXX”或它的某一个依赖项.试图加载格式不正确的程序. 说明: ...