如何在junit4中调用其他类的静态方法@Before
或@Test
?junit4:如何在junit4 @before或@Test中调用其他类的静态方法?
我有一个关于如何在junit4 @Test
或@Before
中调用其他类方法的问题?
例如,我在UtilTool
写了static
方法
public static String readAllBytes(String filePath) {
String content = "";
try {
content = new String(Files.readAllBytes(Paths.get(filePath)));
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
使用在junit4 @Before
的定义方法:
@Before
public void setUp() {
System.out.println("setUp......");
UtilTool.readAllBytes("/tmp/test.txt")
不过,我会收到以下错误消息时我称之为readAllBytes
方法从Junit4的UtilTool
@Before
或@Test
java.lang.NoSuchMethodError: .....
我该如何解决这个问题?
这看起来像一个编译问题给我。你如何建立/运行你的测试? Maven的? –
我只是想法编译我的项目,我不使用maven。 – sagr
如果我在Junit Test类中声明readAllBytes方法,它将会正常工作。 – sagr