Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot run single unit test with JUnit and Eclipse for data-driven testing
    primarykey
    data
    text
    <p>I've stripped the problem from all unnecessary complexity and attached two files for clarity's sake. In actuality, I want to load the required input for testing from a database. In the example I have the suites map in the <code>Suites</code> class, instead of the result from the query. I also have a rather complex comparison instead of the simple one in the run method of <code>TestOverride</code>. Basically that's how I solved creating test suites with their tests from the database (suites map) in a dynamic way. In addition, it is important that I can see the test name when I run it with eclipse.</p> <p>If you run <code>Suites</code> (just right click on it and JUnit-run on eclipse) it works fine. The only test that passes is test4. However, I would like to be able to run a single test with this type of construct (a single suite would be nice as well, but I would be happy with a single test). In other words, after running all suites, I would like to go to the JUnit window, right click on a single test and run it. If I do it it doesn't work. I somehow thought the tests were stored somewhere after the first run and that I could use them later.</p> <p>I am using eclipse 3.6 and JUnit 4.0</p> <p>Any ideas? I don't use annotations for parametrized classes because everything has to be known before compile time (and I take the input from a database). I've also seen in the forums that it's quite a problem renaming the test cases with that approach.</p> <pre><code>import java.util.HashMap; import java.util.Map; import junit.framework.Test; import junit.framework.TestSuite; public class Suites { public static Test suite() { Map&lt;String, String[]&gt; suites = new HashMap&lt;String, String[]&gt;(); suites.put("suite1", new String[]{"test1", "test2"}); suites.put("suite2", new String[]{"test3", "test4"}); TestSuite all = new TestSuite("All Suites"); for(Map.Entry&lt;String, String[]&gt; entry : suites.entrySet()) { TestSuite suite = new TestSuite(entry.getKey()); for(String testName : entry.getValue()) { suite.addTest( new TestOverride( testName ) ); } all.addTest(suite); } return all; } } import junit.framework.AssertionFailedError; import junit.framework.TestCase; import junit.framework.TestResult; public class TestOverride extends TestCase { private String name; public TestOverride( String name) { this.name = name; } @Override public void run(TestResult result) { result.startTest(this); if (this.name.equals("test4")) { result.endTest(this); } else { result.addFailure(this, new AssertionFailedError("Not test4")); } } @Override public String getName() { return name; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload