软件测试实验一.docx

上传人:b****9 文档编号:5554418 上传时间:2022-12-25 格式:DOCX 页数:19 大小:21.59KB
下载 相关 举报
软件测试实验一.docx_第1页
第1页 / 共19页
软件测试实验一.docx_第2页
第2页 / 共19页
软件测试实验一.docx_第3页
第3页 / 共19页
软件测试实验一.docx_第4页
第4页 / 共19页
软件测试实验一.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

软件测试实验一.docx

《软件测试实验一.docx》由会员分享,可在线阅读,更多相关《软件测试实验一.docx(19页珍藏版)》请在冰豆网上搜索。

软件测试实验一.docx

《软件测试》实验报告

一、实验目的

Junit最初是有ErichGamma 和KentBeck编写的一个回归测试框架,为单元测试的支持框架,用来编写和执行重复性的测试,即所谓的白盒测试,Junit是一套框架,继承TestCase类,就可以用Junit进行自动测试。

本次实验就是用Junit框架编写测试用例,进行自动化的白盒测试。

实验包括三道题目:

1DoubleLinkList

2NextDay

3Vector

二、实验要求

1实验环境:

JavaJDK1.7,eclipse;

2在慕测平台提交实验结果;

3提交一份Word版实验报告到ftp,报告内容需包含实验代码;

4本次实验提交截止日期为10月28号晚12点〔写周六晚12点。

三、实验设备〔环境

JDK1.7

EclipseLuna

Eclemma

四、实验内容与结果

1DoubleLinkList

测试类中定义双向链表,考虑清楚其分支情况;

代码:

importstaticrt.*;

import ;

import java.util.ArrayList;

import java.util.Collection;

import org.junit.Test; //双向链表,拥有增加结点,按索引搜寻

 

publicclass DoubleLinkedListTest{

Test

publicvoid test<>{

DoubleLinkedList doubleLinkedList1 = new DoubleLinkedList<>;

doubleLinkedList1.clear<>;

Object object = new Object<>;

doubleLinkedList1.indexOf;

doubleLinkedList1.add;

doubleLinkedList1.indexOf;

Collection collection = new ArrayList<>;

collection.add<"1">;

collection.add<"2">;

collection.add<"3">;

 

DoubleLinkedList doubleLinkedList = new DoubleLinkedList;

//

// assertEquals;

assertEquals>;

assertEquals>;

assertEquals<3, doubleLinkedList.size<>>;

doubleLinkedList.add<"4">;

doubleLinkedList.remove<"4">;

doubleLinkedList.remove<"">;

String s = null;

doubleLinkedList.remove;

doubleLinkedList.add;

doubleLinkedList.remove;

 

assertEquals<"1", doubleLinkedList.get<0>>;

doubleLinkedList.add<0, "999">;

doubleLinkedList.add<4, "999">;

doubleLinkedList.remove<4>;

 

try {

doubleLinkedList.entry<-1>;

} catch {

// TODO:

handleexception

}

try {

doubleLinkedList.entry<5>;

} catch {

// TODO:

handleexception

}

doubleLinkedList.add;

assertEquals<4, doubleLinkedList.indexOf>;

assertEquals<0, doubleLinkedList.indexOf<"999">>;

assertEquals<-1, doubleLinkedList.indexOf<"99">>;

assertEquals<0, doubleLinkedList.lastIndexOf<"999">>;

assertEquals<4, doubleLinkedList.lastIndexOf>;

doubleLinkedList.remove;

assertEquals<-1, doubleLinkedList.lastIndexOf>;

 

doubleLinkedList.repOK<>;

doubleLinkedList.inList>;

doubleLinkedList.inList>;

doubleLinkedList1.inList>;

DoubleLinkedList doubleLinkedList2 = null;

doubleLinkedList1.repOK<>;

Object[] objects ={object};

doubleLinkedList.toArray;

DoubleLinkedList doubleLinkedList3 = new DoubleLinkedList<>;

Object[] objects1 ={object,object,object,object,object,object,object};

doubleLinkedList.toArray;

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

methods>{

// System.out.println>;

// }

assertEquals.previous.repOK<>>;

 

}

}

2NextDay

代码:

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;

date.equals;

date.equals;

date1.equals;

date.equals;

}

}

DayTest

publicvoid getDay<>

{

Yearyear=new Year<4>;

Monthmonth1=new Month<4,year>;

Dayday=new Day<3,month1>;

Dayday1=new Day<28,month1>;

assertEquals,3>;

day1.setCurrentPos<32>;

assertEquals,false>;

assertEquals,true>;

}

Test

publicvoid isValid1<>

{

try{

Monthmonth=null;

Yearyear1=new Year<11>;

Dayday1=new Day<2,month>;

}

catch

{

assertEquals;

}

}

Test

publicvoid isValid2<>

{

try{

Yearyear1=new Year<11>;

Monthmonth2=new Month<10,year1>;

month2.setCurrentPos<13>;

Dayday=new Day<2,month2>;

}catch

{

assertEquals;

}

}

Test

publicvoid isValid3<>

{

try{

Yearyear1=new Year<11>;

Monthmonth2=new Month<10,year1>;

Dayday=new Day<-1,month2>;

}catch

{

assertEquals;

}

}

Test

publicvoid isValid4<>

{

try{

Yearyear1=new Year<11>;

Monthmonth2=new Month<10,year1>;

Dayday=new Day<35,month2>;

}catch

{

assertEquals;

}

}

Test

publicvoid equals<>

{

Yearyear1=new Year<11>;

Monthmonth2=new Month<10,year1>;

Monthmonth3=new Month<11,year1>;

Dayday=new Day<3,month2>;

Dayday1=new Day<4,month2>;

Dayday2=new Day<4,month3>;

Dayday3=new Day<4,month2>;

Objecto=new Object<>;

assertEquals, false>;

assertEquals, false>;

assertEquals, false>;

assertEquals, true>;

assertEquals,3>;

}

}

MonthTest

publicclassMouthTest {

Month month= null;

Year year= null;

Test

publicvoid month<>{

try {

Year year1= newYear<6>;

Month month2= newMonth<6,year1>;

Month month3= newMonth<-3,year1>;

} catch {

assertEquals;

}

}

Test

publicvoid month1<>{

try {

Year year1= newYear<6>;

Month month2= newMonth<15,year1>;

} catch {

assertEquals;

}

}

Test

publicvoid month2<>{

try {

Year year2= newYear<-1>;

year2.setCurrentPos<0>;

Month month5= newMonth<7,year2>;

} catch {

assertEquals;

}

}

Test

publicvoid month3<>{

try {

Month month5= newMonth<7, year>;

} catch {

assertEquals;

}

}

Test

publicvoid getMonth<>{

Year year1= newYear<4>;

Year year2= newYear<5>;

Month m1= newMonth<1,year1>;

Month m2= newMonth<1,year2>;

Month m3= newMonth<12,year2>;

assertEquals,31>;

assertEquals,31>;

assertEquals,1>;

assertEquals, false>;

assertEquals, true>;

}

Test

publicvoid equals<>{

Objecto= new Object<>;

Year year1= newYear<4>;

Year year2= newYear<5>;

Month m1= newMonth<1,year1>;

Month m2= newMonth<1,year2>;

Month m3= newMonth<2,year2>;

Month m4= newMonth<1,year1>;

assertEquals, false>;

assertEquals, false>;

assertEquals, false>;

assertEquals, true>;

}

 

YearTest

publicclassYearTest {

Yearyear1=newYear<1>;

Yearyear2=newYear<1>;

Yearyear3=newYear<2>;

Object s=new Object<>;

Test

publicvoid getYear<>{

assertEquals,1>;

}

Test

publicvoid increment<>{

Yearyear=newYear<-1>;

year.increment<>;

year.increment<>;

assertEquals, true>;

}

Test

publicvoid equals<>

{

assertEquals, true>;

assertEquals, false>;

assertEquals, false>;

}

Test

publicvoid isValid<>

{

try{

Yearyear0=newYear<0>;

}

catch

{

assertEquals;

}

}

Test

publicvoid isLeap<>

{

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, true>;

assertEquals, false>;

assertEquals, false>;

assertEquals, true>;

assertEquals, true>;

assertEquals, true>;

assertEquals,false>;

assertEquals,false>;

assertEquals,true>;

}

}

3)}Vector

Vector是一个可扩展容器

测试类中创建vector实例

代码:

importstatic org.junit.Assert.*;

import java.util.ArrayList;

import java.util.Collection;

import org.junit.Test;

 

publicclass VectorTest{

Test

publicvoid test<>{

Vectorvector = newVector<>;

Vectorvector4 = newVector<1,2>;

try {

Vectorvector2 = newVector<-1,1>;

} catch {

assertEquals;

}

Collection collection = new ArrayList<>;

Object object1 = new Object<>;

Object object2 = new Object<>;

Object object3 = new Object<>;

collection.add;

collection.add;

Vectorvector3 = new Vector;

vector.ensureCapacity<2>;

vector3.ensureCapacity<2>;

vector3.ensureCapacity<3>;

vector4.ensureCapacity<5>;

 

assertEquals<2, vector3.size<>>;

assertEquals>;

assertEquals>;

assertEquals<0, vector3.indexOf>;

vector3.setElementAt;

try {

vector3.setElementAt;

} catch {

assertEquals;

}

vector3.removeElement;

vector3.removeElement;

vector3.addElement;

vector3.removeElementAt<1>;

 

vector3.get<0>;

try {

vector3.get<2>;

} catch {

// TODO:

handleexception

}

try {

vector3.removeElementAt<3>;

} catch {

// TODO:

handleexception

}

try {

vector3.removeElementAt<-1>;

} catch {

// TODO:

handleexception

}

vector3.addElement;

vector3.addElement;

vector3.addElement;

vector3.removeElementAt<2>;

vector3.addElement;

vector3.indexOf;

}

}

五.总结与分析

1.知识薄弱,测试类容易重复

2.分支覆盖

3.画树状图有利于分析代码

 

教师评语:

签名:

日期:

成绩:

展开阅读全文
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1