该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
测试用例的代码:
package testcase;
import huawei.Demo;
import junit.framework.TestCase;
import java.io.*;
import java.util.Vector;
public class DemoTest extends TestCase {
private Demo demo;
private final static String USER_DIR = System.getProperty("user.dir");
private final static String TEST_FOLDER_PATH = USER_DIR + "\\testCase\\";
private final static String TEST_FOLDER_TARGET = TEST_FOLDER_PATH + "target\\";
public void setUp() {
demo = new Demo();
}
private Vector readOutputFile(String filePath) {
Vector vector = new Vector();
try {
FileInputStream fs = new FileInputStream(filePath);
InputStreamReader isr = new InputStreamReader(fs);
BufferedReader br = new BufferedReader(isr);
String data = "";
while ((data = br.readLine()) != null) {
if (data.length() == 0) {
continue;
}
vector.add(data);
}
} catch (FileNotFoundException e) {
throw new RuntimeException("文件路径错误!");
} catch (IOException e) {
throw new RuntimeException("文件读取失败!");
}
return vector;
}
private boolean isSame(String output, String targetPath) {
Vector vector = this.readOutputFile(output);
Vector tgVector = this.readOutputFile(targetPath);
if (vector.size() != tgVector.size()) {
return false;
}
for (int i = 0; i < vector.size(); i++) {
if (!vector.get(i).equals(tgVector.get(i))) {
return false;
}
}
return true;
}
private void testcaseHelper_Should_Fail(String inFilePath, String outFilePath) {
try {
boolean result = demo.attandentSystem(inFilePath, outFilePath);
assertFalse(result);
} catch (Exception e) {
assertTrue(true);
}
}
private void testcaseHelper_Should_Success(String inFilePath, String outFilePath, String targetPath) {
try {
boolean result = demo.attandentSystem(inFilePath, outFilePath);
assertTrue(result);
assertTrue(isSame(outFilePath, targetPath));
} catch (Exception e) {
assertTrue(false);
}
}
public void testcaseSortDate_Case_01() {
testcaseHelper_Should_Success(TEST_FOLDER_PATH + "in.txt", TEST_FOLDER_PATH + "out.txt", TEST_FOLDER_TARGET + "check.txt");
}
}