1.Github地址
https://github.com/chaosrings/wcPro
2.PSP表格
|
PSP2.1 |
PSP阶段 |
预估耗时 (分钟) |
实际耗时 (分钟) |
|
Planning |
计划 |
20 |
20 |
|
· Estimate |
· 估计这个任务需要多少时间 |
20 |
20 |
|
Development |
开发 |
380 |
470 |
|
· Analysis |
· 需求分析 (包括学习新技术) |
20 |
30 |
|
· Design Spec |
· 生成设计文档 |
0 |
0 |
|
· Design Review |
· 设计复审 (和同事审核设计文档) |
0 |
0 |
|
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
30 |
30 |
|
· Design |
· 具体设计 |
30 |
60 |
|
· Coding |
· 具体编码 |
60 |
90 |
|
· Code Review |
· 代码复审 |
60 |
60 |
|
· Test |
· 测试(自我测试,修改代码,提交修改) |
180 |
200 |
|
Reporting |
报告 |
100 |
90 |
|
· Test Report |
· 测试报告 |
60 |
60 |
|
· Size Measurement |
· 计算工作量 |
10 |
10 |
|
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
30 |
20 |
|
|
合计 |
500 |
580 |
3.接口实现
我负责输入控制模块的实现。
设计了一个Scanner类,提供以下接口:
无参构造函数和析构函数:
Scanner()
{
}
~Scanner()
{
}
主要接口:getString()方法
输入参数是txt文件路径的字符串,返回该文件的内容的字符串。
需求要求只处理txt文件,而不处理其他文件,所以做一个判断即可。
如果是txt文件则返回该文件内容的字符串,否则输出提示语,然后返回空字符串。
string getString(const string &path)
{
if (path.substr(path.length() - 4, 4) == ".txt")
{
ifstream in(path);
stringstream buffer;
buffer << in.rdbuf();
string content(buffer.str());
return content;
}
else
{
cout << This is not a ".txg" file !";
}
return "";
}
4.测试用例设计
只需要测试getString()方法
白盒测试:
程序结构简单,只有一个结点,只需设计两个测试用例即可全部覆盖。
| 测试用例 | 预期输出 | 实际输出 |
| test.txt | 成功读取出文件内容的字符串 | 成功读取 |
| test.c | 输出“This is not a ".txt" file !”且返回空字符串 | 输出“This is not a ".txt" file !”且返回空字符串 |
黑盒测试:
需求中要求只处理txt文件,我们根据需求等方面来设计黑盒测试。
如果只分为txt文件和非txt文件,等价类太少实在设计不出20个测试用例。
我们稍微细分一下
| 工作路径 | 其他路径 | |
| 存在的txt文件 | 等价类1 | 等价类2 |
| 存在的非txt文件 | 等价类3 | 等价类4 |
| 不存在的txt文件 | 等价类5 | 等价类6 |
| 不存在的非txt文件 | 等价类7 | 等价类8 |
比如我们测试txt文件与数个非txt文件,它们只有文件格式不同,文件内容全部相同。
| 测试用例 | 预期输出 | 实际输出 |
| blacktest.txt | 成功读取出文件内容的字符串 | 成功读取 |
| blacktest.c | 输出“This is not a ".txt" file !”且返回空字符串 | 输出“This is not a ".txt" file !”且返回空字符串 |
| blacktest.doc | 输出“This is not a ".txt" file !”且返回空字符串 | 输出“This is not a ".txt" file !”且返回空字符串 |
我们测试其他路径下的文件
| 测试用例 | 预期输出 | 实际输出 |
| D:\blacktest.txt | 成功读取出文件内容的字符串 | 成功读取 |
| D:\blacktest.c | 输出“This is not a ".txt" file !”且返回空字符串 | 输出“This is not a ".txt" file !”且返回空字符串 |
| D:\blacktest.doc | 输出“This is not a ".txt" file !”且返回空字符串 | 输出“This is not a ".txt" file !”且返回空字符串 |
我们测试不存在的文件
| 测试用例 | 预期输出 | 实际输出 |
| notexist.txt | 成功读取出文件内容的字符串 | 成功读取(虽然是空串) |
| notexist.c | 输出“This is not a ".txt" file !”且返回空字符串 | 输出“This is not a ".txt" file !”且返回空字符串 |
| notexist.doc | 输出“This is not a ".txt" file !”且返回空字符串 | 输出“This is not a ".txt" file !”且返回空字符串 |
我们测试在其他路径下不存在的文件
| 测试用例 | 预期输出 | 实际输出 |
| D:\notexist.txt | 成功读取出文件内容的字符串 | 成功读取(虽然是空串) |
| D:\notexist.c | 输出“This is not a ".txt" file !”且返回空字符串 | 输出“This is not a ".txt" file !”且返回空字符串 |
| D:\notexist.doc | 输出“This is not a ".txt" file !”且返回空字符串 | 输出“This is not a ".txt" file !”且返回空字符串 |
(就算写了很多感觉不必要的测试用例也不知道怎么凑起20个测试用例了)
5.单元测试脚本
白盒测试:
TEST_CLASS(ScannerWhiteBoxTest)
{
private:
Scanner * scannerTest;
public:
TEST_METHOD_INITIALIZE(setUp)
{
scannerTest = new Scanner();
}
TEST_METHOD_CLEANUP(tearDown)
{
delete scannerTest;
}
TEST_METHOD(TestGetString)
{
Assert::AreEqual<string>("For the witcher,Heartless cold.", scannerTest->getString("test.txt"), L".txt fail");
Assert::AreEqual<string>("", scannerTest->getString("test.c"), L".c fail");
}
};
黑盒测试:
TEST_CLASS(ScannerBlackBoxTest)
{
private:
Scanner * scannerTest;
public:
TEST_METHOD_INITIALIZE(setUp)
{
scannerTest = new Scanner();
}
TEST_METHOD_CLEANUP(tearDown)
{
delete scannerTest;
}
TEST_METHOD(TestGetString)
{
Assert::AreEqual<string>("For the witcher,Heartless cold.", scannerTest->getString("blacktest.txt"), L".txt fail");
Assert::AreEqual<string>("", scannerTest->getString("blacktest.c"), L".c fail");
Assert::AreEqual<string>("", scannerTest->getString("blacktest.doc"), L".doc fail");
Assert::AreEqual<string>("For the witcher,Heartless cold.", scannerTest->getString("D:\\blacktest.txt"), L".txt fail");
Assert::AreEqual<string>("", scannerTest->getString("D:\\blacktest.c"), L".c fail");
Assert::AreEqual<string>("", scannerTest->getString("D:\\blacktest.doc"), L".doc fail");
Assert::AreEqual<string>("", scannerTest->getString("notexist.txt"), L".txt fail");
Assert::AreEqual<string>("", scannerTest->getString("notexist.c"), L".c fail");
Assert::AreEqual<string>("", scannerTest->getString("notexist.doc"), L".doc fail");
Assert::AreEqual<string>("", scannerTest->getString("D:\\notexist.txt"), L".txt fail");
Assert::AreEqual<string>("", scannerTest->getString("D:\\notexist.c"), L".c fail");
Assert::AreEqual<string>("", scannerTest->getString("D:\\notexist.doc"), L".doc fail");
}
};
运行结果:
