软件测试实验一.doc
- 文档编号:18844665
- 上传时间:2024-01-17
- 格式:DOC
- 页数:13
- 大小:57KB
软件测试实验一.doc
《软件测试实验一.doc》由会员分享,可在线阅读,更多相关《软件测试实验一.doc(13页珍藏版)》请在冰点文库上搜索。
.
《软件测试》实验报告
一、实验目的
Junit最初是有ErichGamma和KentBeck编写的一个回归测试框架(regressiontestingframework),为单元测试(UnitTest)的支持框架,用来编写和执行重复性的测试,即所谓的白盒测试,Junit是一套框架,继承TestCase类,就可以用Junit进行自动测试。
本次实验就是用Junit框架编写测试用例,进行自动化的白盒测试。
实验包括三道题目:
1〕DoubleLinkList
2〕NextDay
3〕Vector
二、实验要求
1〕实验环境:
JavaJDK1.7,eclipse;
2〕在慕测平台提交实验结果;
3〕提交一份Word版实验报告到ftp,报告内容需包含实验代码;
4〕本次实验提交截止日期为10月28号晚12点〔写周六晚12点〕。
三、实验设备〔环境〕
JDK1.7
EclipseLuna
Eclemma
四、实验内容与结果
1〕DoubleLinkList
测试类中定义双向链表,考虑清楚其分支情况;
代码:
importstaticorg.junit.Assert.*;
import;
importjava.util.ArrayList;
importjava.util.Collection;
importorg.junit.Test;//双向链表,拥有增加结点,按索引搜寻
publicclassDoubleLinkedListTest{
Test
publicvoidtest(){
DoubleLinkedListdoubleLinkedList1=newDoubleLinkedList();
doubleLinkedList1.clear();
Objectobject=newObject();
doubleLinkedList1.indexOf(object);
doubleLinkedList1.add(object);
doubleLinkedList1.indexOf(object);
Collection
collection.add("1");
collection.add("2");
collection.add("3");
DoubleLinkedListdoubleLinkedList=newDoubleLinkedList(collection);
//
// assertEquals(true,actual);
assertEquals(true,doubleLinkedList.contains("1"));
assertEquals(false,doubleLinkedList.contains(null));
assertEquals(3,doubleLinkedList.size());
doubleLinkedList.add("4");
doubleLinkedList.remove("4");
doubleLinkedList.remove("");
Strings=null;
doubleLinkedList.remove(s);
doubleLinkedList.add(null);
doubleLinkedList.remove(s);
assertEquals("1",doubleLinkedList.get(0));
doubleLinkedList.add(0,"999");
doubleLinkedList.add(4,"999");
doubleLinkedList.remove(4);
try{
doubleLinkedList.entry(-1);
}catch(Exceptione){
//TODO:
handleexception
}
try{
doubleLinkedList.entry(5);
}catch(Exceptione){
//TODO:
handleexception
}
doubleLinkedList.add(null);
assertEquals(4,doubleLinkedList.indexOf(null));
assertEquals(0,doubleLinkedList.indexOf("999"));
assertEquals(-1,doubleLinkedList.indexOf("99"));
assertEquals(0,doubleLinkedList.lastIndexOf("999"));
assertEquals(4,doubleLinkedList.lastIndexOf(null));
doubleLinkedList.remove(s);
assertEquals(-1,doubleLinkedList.lastIndexOf(null));
doubleLinkedList.repOK();
doubleLinkedList.inList(doubleLinkedList.entry(0));
doubleLinkedList.inList(doubleLinkedList.entry
(1));
doubleLinkedList1.inList(doubleLinkedList.entry(0));
DoubleLinkedListdoubleLinkedList2=null;
doubleLinkedList1.repOK();
Object[]objects={object};
doubleLinkedList.toArray(objects);
DoubleLinkedListdoubleLinkedList3=newDoubleLinkedList();
Object[]objects1={object,object,object,object,object,object,object};
doubleLinkedList.toArray(objects1);
collection.clear();
doubleLinkedList3.addAll(0,collection);
doubleLinkedList3.addAll(4,collection);
doubleLinkedList1.addAll(1,collection);
doubleLinkedList1.addAll(55,collection);
// Class
>c=DoubleLinkedList.class;
// Method[]methods=c.getDeclaredMethods();
// for(Methodm:
methods){
// System.out.println(m.getName());
// }
assertEquals(true,doubleLinkedList.entry(3).previous.repOK());
}
}
2〕NextDay
代码:
DateTest:
publicclassDateTest{
Test
publicvoidtest(){
Datedate=newDate(1,2,8);
Datedate1=newDate(1,31,4);
Datedate2=newDate(12,31,4);
date.getDay();
date.getMonth();
date.getYear();
date.increment();
date1.increment();
date2.increment();
date.toString();
date.printDate();
date.equals(date1);
date.equals(date2);
date.equals(null);
date1.equals(date2);
date.equals(date);
}
}
DayTest
publicvoidgetDay()
{
Yearyear=newYear(4);
Monthmonth1=newMonth(4,year);
Dayday=newDay(3,month1);
Dayday1=newDay(28,month1);
assertEquals(day.getCurrentPos(),3);
day1.setCurrentPos(32);
assertEquals(day1.increment(),false);
assertEquals(day.increment(),true);
}
Test
publicvoidisValid1()
{
try{
Monthmonth=null;
Yearyear1=newYear(11);
Dayday1=newDay(2,month);
}
catch(Exceptiono)
{
assertEquals(oinstanceofIllegalArgumentException,true);
}
}
Test
publicvoidisValid2()
{
try{
Yearyear1=newYear(11);
Monthmonth2=newMonth(10,year1);
month2.setCurrentPos(13);
Dayday=newDay(2,month2);
}catch(Exceptiono)
{
assertEquals(oinstanceofIllegalArgumentException,true);
}
}
Test
publicvoidisValid3()
{
try{
Yearyear1=newYear(11);
Monthmonth2=newMonth(10,year1);
Dayday=newDay(-1,month2);
}catch(Exceptiono)
{
assertEquals(oinstanceofIllegalArgumentException,true);
}
}
Test
publicvoidisValid4()
{
try{
Yearyear1=newYear(11);
Monthmonth2=newMonth(10,year1);
Dayday=newDay(35,month2);
}catch(Exceptiono)
{
assertEquals(oinstanceofIllegalArgumentException,true);
}
}
Test
publicvoidequals()
{
Yearyear1=newYear(11);
Monthmonth2=newMonth(10,year1);
Monthmonth3=newMonth(11,year1);
Dayday=newDay(3,month2);
Dayday1=newDay(4,month2);
Dayday2=newDay(4,month3);
Dayday3=newDay(4,month2);
Objecto=newObject();
assertEquals(day.equals(o),false);
assertEquals(day.equals(day1),false);
assertEquals(day1.equals(day2),false);
assertEquals(day1.equals(day3),true);
assertEquals(day.getDay(),3);
}
}
MonthTest
publicclassMouthTest{
Monthmonth=null;
Yearyear=null;
Test
publicvoidmonth(){
try{
Yearyear1=newYear(6);
Monthmonth2=newMonth(6,year1);
Monthmonth3=newMonth(-3,year1);
}catch(Exceptione){
assertEquals(einstanceofIllegalArgumentException,true);
}
}
Test
publicvoidmonth1(){
try{
Yearyear1=newYear(6);
Monthmonth2=newMonth(15,year1);
}catch(Exceptione){
assertEquals(einstanceofIllegalArgumentException,true);
}
}
Test
publicvoidmonth2(){
try{
Yearyear2=newYear(-1);
year2.setCurrentPos(0);
Monthmonth5=newMonth(7,year2);
}catch(Exceptione){
assertEquals(einstanceofIllegalArgumentException,true);
}
}
Test
publicvoidmonth3(){
try{
Monthmonth5=newMonth(7,year);
}catch(Exceptione){
assertEquals(einstanceofIllegalArgumentException,true);
}
}
Test
publicvoidgetMonth(){
Yearyear1=newYear(4);
Yearyear2=newYear(5);
Monthm1=newMonth(1,year1);
Monthm2=newMonth(1,year2);
Monthm3=newMonth(12,year2);
assertEquals(m1.getMonthSize(),31);
assertEquals(m2.getMonthSize(),31);
assertEquals(m1.getMonth(),1);
assertEquals(m3.increment(),false);
assertEquals(m1.increment(),true);
}
Test
publicvoidequals(){
Objecto=newObject();
Yearyear1=newYear(4);
Yearyear2=newYear(5);
Monthm1=newMonth(1,year1);
Monthm2=newMonth(1,year2);
Monthm3=newMonth(2,year2);
Monthm4=newMonth(1,year1);
assertEquals(m1.equals(m2),false);
assertEquals(m1.equals(m3),false);
assertEquals(m1.equals(o),false);
assertEquals(m1.equals(m4),true);
}
YearTest
publicclassYearTest{
Yearyear1=newYear
(1);
Yearyear2=newYear
(1);
Yearyear3=newYear
(2);
Objects=newObject();
Test
publicvoidgetYear(){
assertEquals(year1.getYear(),1);
}
Test
publicvoidincrement(){
Yearyear=newYear(-1);
year.increment();
year.increment();
assertEquals(year1.increment(),true);
}
Test
publicvoidequals()
{
assertEquals(year1.equals(year2),true);
assertEquals(year1.equals(year3),false);
assertEquals(year1.equals(s),false);
}
Test
publicvoidisValid()
{
try{
Yearyear0=newYear(0);
}
catch(Exceptiono)
{
assertEquals(oinstanceofIllegalArgumentException,true);
}
}
Test
publicvoidisLeap()
{
Yeara1=newYear(4);
Yeara2=newYear(100);
Yeara3=newYear(5);
Yeara4=newYear(400);
Yeara5=newYear(-1);
Yeara6=newYear(-401);
Yeara7=newYear(-2);
Yeara8=newYear(-101);
Yeara9=newYear(-5);
assertEquals(a1.isLeap(),true);
assertEquals(a2.isLeap(),false);
assertEquals(a3.isLeap(),false);
assertEquals(a4.isLeap(),true);
assertEquals(a5.isLeap(),true);
assertEquals(a6.isLeap(),true);
assertEquals(a7.isLeap(),false);
assertEquals(a8.isLeap(),false);
assertEquals(a9.isLeap(),true);
}
}
3)}Vector
Vector是一个可扩展容器
测试类中创建vector实例
代码:
importstaticorg.junit.Assert.*;
importjava.util.ArrayList;
importjava.util.Collection;
importorg.junit.Test;
publicclassVectorTest{
Test
publicvoidtest(){
Vectorvector=newVector();
Vectorvector4=newVector(1,2);
try{
Vectorvector2=newVector(-1,1);
}catch(Exceptione){
assertEquals(true,einstanceofIllegalArgumentException);
}
Collection
Objectobject1=newObject();
Objectobject2=newObject();
Objectobject3=newObject();
collection.add(object1);
collection.add(object2);
Vectorvector3=newVector(collection);
vector.ensureCapacity
(2);
vector3.ensureCapacity
(2);
vector3.ensureCapacity(3);
vector4.ensureCapacity(5);
assertEquals(2,vector3.size());
assertEquals(true,vector3.contains(object1));
assertEquals(false,vector3.contains(null));
assertEquals(0,vector3.indexOf(object1));
vector3.setElementAt(object2,1);
try{
vector3.setElementAt(object2,2);
}catch(Exceptione){
assertEquals(true,einstanceofArrayIndexOutOfBoundsException);
}
vector3.removeElement(object2);
vector3.removeElement(object3);
vector3.addElement(object2);
vector3.removeElementAt
(1);
vector3.get(0);
try{
vector3.get
(2);
}catch(Exceptione){
//TODO:
handleexception
}
try{
vector3.removeElementAt(3);
}catch(Exceptio
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 软件 测试 实验
![提示](https://static.bingdoc.com/images/bang_tan.gif)