我对TDD很新.我看到一些文档说关于阳性测试,阴性测试,边界测试等.任何人都可以告诉我阳性测试和阴性测试之间的区别吗?是否有任何关于不同类型测试的参考?(我不是在找书)
===============================================================
| Positive Test Case | Negative Test Case |
+==============================+==============================+
| test by valid/expected data | test by invalid data |
+------------------------------+------------------------------+
| check if the function does | check if the function does |
| that it should do | not that it should not do |
+------------------------------+------------------------------+
| examine general behaviors of | examine if the function |
| the function | is fault proof (does not |
| | crush/mis-response in bad |
| | situations) |
===============================+===============================
Run Code Online (Sandbox Code Playgroud)
一些简单的示例将帮助您更清楚地了解差异。
候选功能:
public boolean deleteFile(String filePath) {
// try to delete the file; and
// return true for success, false for failure
}
Run Code Online (Sandbox Code Playgroud)
正测试用例-由于此功能需要文件路径,因此正测试用例将包含所有可能的有效文件路径:
public void deleteFile_forAbsoluteFilePath_P() {
String filePath = "D:\\Temp\\file.txt";
// create file, call deleteFile(), and check if really deleted
}
public void deleteFile_forRelativeFilePath_P() {
String filePath = "file.txt";
// create file, call deleteFile(), and check if really deleted
}
public void deleteFile_forNonExistingFilePath_P() {
String filePath = "wHSyY#zP_04l.txt";
// call deleteFile(), and check if false is returned
}
public void deleteFile_forSymlinkedFilePath_P() {
String filePath = "D:\\Temp\\symlink\\dir\\file.txt";
// create file, create symlink, delete file, and
// check if really deleted
}
public void deleteFile_forUndeletableFile_P() {
String filePath = "file.bin";
// create file, restrict delete permission, call deleteFile(), and
// check if does not crash and returns false
}
Run Code Online (Sandbox Code Playgroud)
否定测试用例-可以发送到该函数且无效的任何事物都将处于否定测试用例中:
public void deleteFile_forAlreadyDeletedFile_N() {
String filePath = "file.bin";
// create file, call deleteFile() twice, and
// for second time check if does not crash and returns false
}
public void deleteFile_forDirectoryPath_N() {
String dirPath = "D:\\Temp\\dir";
// create directory, call deleteFile(), and check if false is returned
}
public void deleteFile_forSymlinkedDirectoryPath_N() {
String symlink = "D:\\Temp\\symlink";
// create symlink, call deleteFile(), and check if false is returned
}
public void deleteFile_forNullString_N() {
String filePath = NULL;
// call deleteFile(), and check if does not crash and returns false
}
public void deleteFile_forCorruptedFilePath_N() {
String filePath = "D:\\Tem¡¿ÿ¿";
// call deleteFile(), and check if does not crash and returns false
}
Run Code Online (Sandbox Code Playgroud)
单元测试还可以作为功能的实时文档。因此,否定测试用例应该只包含预期的例外条件,而不是将所有可能的参数扔给函数。
因此,无需对此进行测试-