软件测试实验一.docx

上传人:聆听****声音 文档编号:5914922 上传时间:2023-05-09 格式:DOCX 页数:15 大小:31.77KB
下载 相关 举报
软件测试实验一.docx_第1页
第1页 / 共15页
软件测试实验一.docx_第2页
第2页 / 共15页
软件测试实验一.docx_第3页
第3页 / 共15页
软件测试实验一.docx_第4页
第4页 / 共15页
软件测试实验一.docx_第5页
第5页 / 共15页
软件测试实验一.docx_第6页
第6页 / 共15页
软件测试实验一.docx_第7页
第7页 / 共15页
软件测试实验一.docx_第8页
第8页 / 共15页
软件测试实验一.docx_第9页
第9页 / 共15页
软件测试实验一.docx_第10页
第10页 / 共15页
软件测试实验一.docx_第11页
第11页 / 共15页
软件测试实验一.docx_第12页
第12页 / 共15页
软件测试实验一.docx_第13页
第13页 / 共15页
软件测试实验一.docx_第14页
第14页 / 共15页
软件测试实验一.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

软件测试实验一.docx

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

软件测试实验一.docx

《软件测试》实验报告

一、实验目的

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

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

代码:

importstatic org.junit.Assert.*;

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(object);

doubleLinkedList1.add(object);

doubleLinkedList1.indexOf(object);

Collection collection = new ArrayList();

collection.add("1");

collection.add("2");

collection.add("3");

 

DoubleLinkedList doubleLinkedList = new DoubleLinkedList(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("");

String s = 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 (Exception e){

// TODO:

handleexception

}

try {

doubleLinkedList.entry(5);

} catch (Exception e){

// 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));

DoubleLinkedList doubleLinkedList2 = null;

doubleLinkedList1.repOK();

Object[] objects ={object};

doubleLinkedList.toArray(objects);

DoubleLinkedList doubleLinkedList3 = new DoubleLinkedList();

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

publicvoid getDay()

{

Yearyear=new Year(4);

Monthmonth1=new Month(4,year);

Dayday=new Day(3,month1);

Dayday1=new Day(28,month1);

assertEquals(day.getCurrentPos(),3);

day1.setCurrentPos(32);

assertEquals(day1.increment(),false);

assertEquals(day.increment(),true);

}

Test

publicvoid isValid1()

{

try{

Monthmonth=null;

Yearyear1=new Year(11);

Dayday1=new Day(2,month);

}

catch(Exceptiono)

{

assertEquals(o instanceof IllegalArgumentException, true);

}

}

Test

publicvoid isValid2()

{

try{

Yearyear1=new Year(11);

Monthmonth2=new Month(10,year1);

month2.setCurrentPos(13);

Dayday=new Day(2,month2);

}catch(Exceptiono)

{

assertEquals(o instanceof IllegalArgumentException, true);

}

}

Test

publicvoid isValid3()

{

try{

Yearyear1=new Year(11);

Monthmonth2=new Month(10,year1);

Dayday=new Day(-1,month2);

}catch(Exceptiono)

{

assertEquals(o instanceof IllegalArgumentException, true);

}

}

Test

publicvoid isValid4()

{

try{

Yearyear1=new Year(11);

Monthmonth2=new Month(10,year1);

Dayday=new Day(35,month2);

}catch(Exceptiono)

{

assertEquals(o instanceof IllegalArgumentException, true);

}

}

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(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 {

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 (Exceptione){

assertEquals(e instanceof IllegalArgumentException, true);

}

}

Test

publicvoid month1(){

try {

Year year1= newYear(6);

Month month2= newMonth(15,year1);

} catch (Exceptione){

assertEquals(e instanceof IllegalArgumentException, true);

}

}

Test

publicvoid month2(){

try {

Year year2= newYear(-1);

year2.setCurrentPos(0);

Month month5= newMonth(7,year2);

} catch (Exceptione){

assertEquals(e instanceof IllegalArgumentException, true);

}

}

Test

publicvoid month3(){

try {

Month month5= newMonth(7, year);

} catch (Exceptione){

assertEquals(e instanceof IllegalArgumentException, true);

}

}

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(m1.getMonthSize(),31);

assertEquals(m2.getMonthSize(),31);

assertEquals(m1.getMonth(),1);

assertEquals(m3.increment(), false);

assertEquals(m1.increment(), 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(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);

Object s=new Object();

Test

publicvoid getYear(){

assertEquals(year1.getYear(),1);

}

Test

publicvoid increment(){

Yearyear=newYear(-1);

year.increment();

year.increment();

assertEquals(year1.increment(), true);

}

Test

publicvoid equals()

{

assertEquals(year1.equals(year2), true);

assertEquals(year1.equals(year3), false);

assertEquals(year1.equals(s), false);

}

Test

publicvoid isValid()

{

try{

Yearyear0=newYear(0);

}

catch(Exception o)

{

assertEquals(oinstanceof IllegalArgumentException, true);

}

}

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(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实例

代码:

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 (Exception e){

assertEquals(true, einstanceof IllegalArgumentException);

}

Collection collection = new ArrayList();

Object object1 = new Object();

Object object2 = new Object();

Object object3 = new Object();

collection.add(object1);

collection.add(object2);

Vectorvector3 = new Vector(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 (Exception e){

assertEquals(true, einstanceof ArrayIndexOutOfBoundsException);

}

vector3.removeElement(object2);

vector3.removeElement(object3);

vector3.addElement(object2);

vector3.removeElementAt

(1);

 

vector3.get(0);

try {

vector3.get

(2);

} catch (Exception e){

// TODO:

handleexception

}

try {

vector3.removeElementAt(3);

} catch (Exception e){

// TODO:

handleexception

}

try {

vector3.removeElementAt(-1);

} catch (Exception e){

// TODO:

handleexception

}

vector3.addElement(object2);

vector3.addElement(object2);

vector3.addElement(object2);

vector3.removeElementAt

(2);

vector3.addElement(null);

vector3.indexOf(null,1);

}

}

五.总结与分析

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

2.分支覆盖

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

 

教师评语:

签名:

日期:

成绩:

展开阅读全文
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2