这是我写的功能:
private String getPatternFromLogFile() {
final File dir = new File(".");
try {
String fileContents = readFile(dir.getCanonicalPath()
+ "\\sshxcute.log");
Pattern patternDefinition = Pattern.compile(
".*Start to run command(.*)Connection channel closed",
Pattern.DOTALL);
Matcher inputPattern = patternDefinition.matcher(fileContents);
if (inputPattern.find()) {
return inputPattern.group(1);
}
} catch (IOException e) {
LOGGER.log(Level.DEBUG, e.getMessage());
}
return "";
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试获取文件"sshxcute.log"的内容.
readFile()是这个类本身的一个函数.
我想编写一个测试用例,它进入if块内并返回我想要的任何内容,以便我可以断言它.
这是正确的方法吗?
有人可以帮我写JUnit吗?我是JUnit的新手,任何帮助都会很棒.
谢谢.