Java 在单独的代码上运行单元测试
我在这一点上不知所措,我真的不知道如何解释它,但我会尽我最大的努力 我有一个项目,客户希望我创造一个竞争对手。一个人必须上传他的Java代码,另一个人必须上传他的JUnit测试。 我的应用程序应该获取这2个文件,并在上传的代码上运行上传的测试 现在我知道了如何让用户上传他们的文件,但我一点也不知道如何运行测试。有人能帮我解决这个问题吗 以下是我目前掌握的代码:Java 在单独的代码上运行单元测试,java,unit-testing,junit,automated-tests,Java,Unit Testing,Junit,Automated Tests,我在这一点上不知所措,我真的不知道如何解释它,但我会尽我最大的努力 我有一个项目,客户希望我创造一个竞争对手。一个人必须上传他的Java代码,另一个人必须上传他的JUnit测试。 我的应用程序应该获取这2个文件,并在上传的代码上运行上传的测试 现在我知道了如何让用户上传他们的文件,但我一点也不知道如何运行测试。有人能帮我解决这个问题吗 以下是我目前掌握的代码: public void actionPerformed(ActionEvent e) { if (e.getSource()
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == codeB)
{
//Get the code
File dir = new File("..");
fc.setCurrentDirectory(dir);
int returnVal = fc.showOpenDialog(this);
if (returnVal == fc.APPROVE_OPTION)
{
codeF = fc.getSelectedFile();
codeV.setText(codeF.getPath());
}
else
{
System.out.println("Cancel");
}
}
if (e.getSource() == testB)
{
//Get the test
File dir = new File("..");
fc.setCurrentDirectory(dir);
int returnVal = fc.showOpenDialog(this);
if (returnVal == fc.APPROVE_OPTION)
{
testF = fc.getSelectedFile();
testV.setText(testF.getPath());
}
else
{
System.out.println("Cancel");
}
}
if (e.getSource() == run)
{
//Run the tests on the code
}
您的代码片段与您的问题完全无关 你要做的是:
JUnitCore junit = new JUnitCore();
Result result = junit.runClasses(testClasses); // testClasses is the array of test classes to be executed
可能是复制品我整天都在试着让它工作,但我不能让它太工作。我正在使用JDK,但它总是失败,加载类。这个问题有用吗?