我正在尝试使用Powershell脚本执行Junit测试。但是我不断收到初始化错误(SLLTest):没有可运行的方法
相同的测试用例在Eclipse中运行良好。我还要重写类路径,以在编译和执行期间使用与eclipse相同的jars。
// TestRunner
var vm = require("vm");
var fs = require("fs");
var data = fs.readFileSync("generatedModels.js");
var window = {};
vm.runInNewContext(data, window, "generatedModels.js");
//测试类之一
import java.io.PrintStream;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestRunner {
public static void main(String[] args) {
PrintStream original = System.out;
Result result = JUnitCore.runClasses(TestSuite.class);
System.setOut(original);
for(Failure failure : result.getFailures())
System.out.println(failure);
if(result.wasSuccessful())
System.out.println("Success");
}
}
//测试套件类
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test;
public class StackQTest{
StackQ s = new StackQ();
@Test
public void pushPopTest() {
s.push(1);
s.push(2);
s.push(3);
s.push(4);
s.push(5);
assertEquals(5, s.pop());
assertEquals(4, s.pop());
assertEquals(3, s.pop());
assertEquals(2, s.pop());
assertEquals(1, s.pop());
}
}
我期望“ Success”作为输出,我总是得到:
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith (Suite.class)
@SuiteClasses ({SLLTest.class, DLLTest.class, RecursionTest.class,
QueueSTest.class, StackQTest.class})
public class TestSuite {
}