软件变异体测试(mutation test)

来源:互联网 发布:java中获取unix时间戳 编辑:程序博客网 时间:2024/04/27 17:20

首先给出一个Web工具帮助搞软件测试研究的人员类实现:graph coverage,edge-pair coverage,prime path coverage,logic coverage

http://cs.gmu.edu:8080/offutt/coverage/DFGraphCoverage

关于Prime Path 的Test Path实现算法见论文:Better Algorithms to Minimize the Cost of Test Paths

编异体测试可使用的工具有:

1.uJava,这是一个用java语言开发的辅助实现变体测试的工具,由Jeff offutt等教授合作开发的,具体见官网:http://cs.gmu.edu/~offutt/mujava/#Links

该网站上提供了详细的uJava介绍信息和uJava的下载,及如何配置环境变量和使用方法。

2.muclipse也是一个实现变异体测试的工具,它是在uJava工具的基础上开发出来的一个可以用在Eclipse环境中的一个小插件,对于熟练使用Eclipse工具来编程的人来说,在Eclipse框架中添加插件来扩展器功能是一个常见而深受喜欢的方式。而muclipse正是这样一个java插件,它和uJava相比显然方便的使用者(配置环境时明显感觉到工作量小很多,而且和其他插件的配置方式保持一致,几乎没有难度,成功率很高)。但是muclipse有一个要求,就是开发者的TestJava类必须是采用JUnit来生成的,及测试类必须符合JUnit的结构要求,这样的话虽然在编写测试类时比uJava多了些限制,但用JUnit也是一个很好的方式,这是程序员在单元测试时普遍采用的方式,且借助Eclipse来方便生成JUnit测试类的框架,程序员只需填写测试代码,工作量也减少了很多。该方面介绍具体见:http://muclipse.sourceforge.net/index.php

该网页上提供了muclipse工具的介绍信息,安装方法,包的下载和使用方法,及结果展示,很详细。(补充:JUnit采用版本3和版本4都是可以的)


下面另附一个例子程序:

例子类(WordDeilUtil

package com;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class WordDeilUtil {

public static String wordFormat4DB(String name) {
if (name == null)
return null;
Pattern p = Pattern.compile("[A-Z]");
Matcher m = p.matcher(name);
StringBuffer sb = new StringBuffer();
while (m.find()) {
if (m.start() == 0)
m.appendReplacement(sb, m.group());
else
m.appendReplacement(sb, "_" + m.group());
}
return m.appendTail(sb).toString().toLowerCase();
}

}

测试类(WordDeilUtilTest),采用JUint4

package test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.WordDeilUtil;

public class WordDeilUtilTest {

@Before
public void setUp() throws Exception {
}


@After
public void tearDown() throws Exception {
}

@Test
public void wordFormat4DBNormal(){
String target="employeeInfo";
String result=WordDeilUtil.wordFormat4DB(target);
assertEquals(result,"employee_info");
}

@Test
public void wordFormat4DBNull(){
String target=null;
String result=WordDeilUtil.wordFormat4DB(target);
assertNull(result);
}

@Test
public void wordFormat4DBEmpty(){
String target="";
String result=WordDeilUtil.wordFormat4DB(target);
assertEquals(result,"");
}

@Test
public void wordFormat4DBBegin(){
String target="EmployeeInfo";
String result=WordDeilUtil.wordFormat4DB(target);
assertEquals(result,"employee_info");
}

@Test
public void wordFormat4DBEnd(){
String target="employeeInfoA";
String result=WordDeilUtil.wordFormat4DB(target);
assertEquals(result,"employee_info_a");
}

@Test
public void wordFormat4DBTogether(){
String target="employeeAInfo";
String result=WordDeilUtil.wordFormat4DB(target);
assertEquals(result,"employee_a_info");
}
}

下面给出WordDeilUtil项目的目录结构:



原创粉丝点击