50,526
社区成员
发帖
与我相关
我的任务
分享
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<String> readOutputFile(String filePath) {
Vector<String> vector = new Vector<String>();
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<String> vector = this.readOutputFile(output);
Vector<String> 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");
}
}
package huawei;
public final class Demo {
/**
* 考勤系统:统计考勤时间
* @param inFilePath
* @param outFilePath
* @return 正常返回true,异常返回false
*/
public boolean attandentSystem(String inFilePath, String outFilePath)
{
return true;
}
}
package huawei;
public final class Demo {
/**
* 考勤系统:统计考勤时间
* @param inFilePath
* @param outFilePath
* @return 正常返回true,异常返回false
*/
public boolean attandentSystem(String inFilePath, String outFilePath)
{
return true;
}
}
public class Hello{
static{
System.out.println("hello");
}
}