【软件测试】JAVA PATH FINDER [JPF]

软件测试小组作业之JPF 首先先说说JPF是个什么东西 官方给出的解释: JPF核心是用于Java™字节码的虚拟机(VM),这意味着它是一个程序,您可以让Java程序执行。它用于在这些程序中找到缺陷,因此您还需要给出属性以作为输入进行检查。 JPF通过一份报告来回复,该报告说如果属性持有和/或由JPF创建的验证工件进行进一步分析(如测试用例)。 JPF是一个有几个扭曲的虚拟机。它在Java本身中实现,所以不要指望它像您的普通Java一样快速运行。它是在VM上运行的VM。虽然Java字节码的执行语义在http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html/ Sun的Java虚拟机规范中有明确定义,但我们在JPF中几乎没有硬连线语义 - VM指令集由一组可被替换的类表示。 默认指令集使用下一个JPF功能:执行选项。 JPF可以识别您的程序中的执行可能不同的进程,然后系统地探索所有这些点。这意味着JPF(理论上)通过程序执行所有路径,而不仅仅是像普通的VM那样。典型的选择是不同的调度序列或随机值,但JPF可以再次介绍您自己的类型,如用户输入或statemachine事件。 个人觉得JPF是一个针对JAVA程序寻找可执行路径的工具。看了一下官方的例子,觉得JPF可以在JAVA程序执行时自动检测所有的可执行路径,找到可能出现问题的路径。不同于传统的基于用例的Testing,JPF采用的是Model Checking,尽管基于用例的测试在用例足够多的时候有着很不错的测试效果,但是很难保证测试到所有的可行路径。JPF官方给出了基于测试用例的Testing 与 Model Testing 的差别:     阅读全文
Liebes's avatar
Liebes 4月 08, 2017

【软件测试】作业3 测试之路径覆盖

书上的练习题,要求设计相应的测试用例,写出主路径覆盖 Problem Description Answer Problem Description /*********************************** * Finds and prints n prime integers * Jeff Offutt, Spring 2003 ************************************/ private static void printPrimes (int n){ int curPrime; // Value currently considered for primeness int numPrimes; // Number of primes found so far. boolean isPrime; // Is curPrime prime? int [] primes = new int [MAXPRIMES]; // The list of prime numbers. // Initialize 2 into the list of primes. primes[0] = 2; numPrimes = 1; curPrime = 2; while(numPrimes < n){ curPrime++; //next number to consider ... isPrime = true; for(int i = 0; i <= numPrime-1; i++){ if(isDivisible(primes[i], curPrime)){ isPrime = false; ...     阅读全文
Liebes's avatar
Liebes 3月 15, 2017

【软件测试】作业2 设计测试用例

软件测试课程作业,按照要求设计相关的测试用例 问题描述 问题解答 问题描述 Below are two faulty programs. Each includes a test case that results in failure. Answer the following questions about each program. // program 1 public int findLast (int[] x, int y) { //Effects: If x==null throw NullPointerException // else return the index of the last element // in x that equals y. // If no such element exists, return -1 for (int i=x.length-1; i > 0; i--){ if (x[i] == y){ return i; } } return -1; } / test: x=[2, 3, 5]; y = 2 / Expected = 0 // program 2 public static int lastZero (int[] x) { // Effects: if x==null throw NullPointerException // else return the index of the LAST 0 in x. // Return -1 if 0 does not occur in x for (int i = 0; i < x.length; i++){ if (x[i] == 0){ return i; } } return -1; } // test: x=[0, 1, 0] // Expected = 2     阅读全文
Liebes's avatar
Liebes 2月 26, 2017

【软件测试】记录几个曾经遇到的坑

php中过滤函数的编码问题 mysql不经过滤直接拼接的问题 php中过滤函数的编码问题问题发生的背景是整理服务器,将一部分php5的代码迁移到php7的服务器上。 If omitted, the default value of the encoding varies depending on the PHP version in use. In 5.6 and later, the default_charset configuration option is used as the default value. PHP 5.4 and 5.5 will use UTF-8 as the default. Earlier versions of PHP use ISO-8859-1. 这是官方的文档,能看到在php5.6之前与之后 string htmlspecialchars ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get("default_charset") [, bool $double_encode = true ]]] ) 这个函数的默认编码变了,使得当在php5.6之后的版本,该函数无法对编码格式为gbk的进行过滤。需要显示定义 string $encoding = ini_get("default_charset")这个参数。 mysql不经过滤直接拼接的问题这个则是蠢得不行不行的bug,懂点的人都知道mysql如果直接拼接字符串会导致各种注入问题。比如:     阅读全文
Liebes's avatar
Liebes 2月 26, 2017