I have a java project created on netbeans, the project has some test in project's test packages.
I have different behaviors when I test the project via Project->Menu->Test and test via creating junit4Suite with all class Test files.
For example, one difference is the velocity:
- testing via suite: 58 test (all) takes 2.7 seconds
- testing via Project->Menu->Test: 58 test(all) takes 14.9 seconds
What happens in background when netbeans is testing the project via Project->Menu->Test?
EDIT:
The project is very small so the time netbeans takes before execute testing are around 1 second.
Another diference:
I have created another dummy project with a method that you can only run once:
public class ScriptThreadWorker {
private static ScriptThreadWorker worker;
private Thread thread;
public static ScriptThreadWorker getWorker() {
if (worker == null) {
worker = new ScriptThreadWorker();
}
return worker;
}
public void runOnScriptThread(Runnable task) {
if (thread != null) {
throw new RuntimeException("you can run once");
}
thread = new Thread(task);
thread.setName("ui-thread");
thread.start();
}
}
And I have created 2 identical 2 test classes with a junit suite:
ScriptThreadWorker1Test.java
public class ScriptThreadWorker1Test {
@Test
public void testRun1() {
ScriptThreadWorker.getWorker().runOnScriptThread(new Runnable() {
@Override
public void run() {
// do nothing
}
});
}
}
ScriptThreadWorker2Test.java
public class ScriptThreadWorker2Test {
@Test
public void testRun1() {
ScriptThreadWorker.getWorker().runOnScriptThread(new Runnable() {
@Override
public void run() {
// do nothing
}
});
}
}
NewTestSuite.java
@RunWith(Suite.class)
@Suite.SuiteClasses({
javaapplication3.ScriptThreadWorker2Test.class,
javaapplication3.ScriptThreadWorker1Test.class})
public class NewTestSuite {
}
When I execute the test via Project->Menu->Test: "Both test passed"
But when I execute the test via NewTestSuite.java->Menu->Test file: "1 test passed, 1 test caused an error, you can run once".