Hans En
Hans En

Reputation: 926

Showing JUnit view in Eclipse when running tests from Code

When I run just my Testclass in Eclipse I get the JUnit view showing the tree structure and if the test was successful. If I start my Test from code:

JUnitCore core = new JUnitCore();
core.run(SimpleTests.class);

the view does not show. Can I change this?

Upvotes: 4

Views: 16239

Answers (5)

bigcitylife
bigcitylife

Reputation: 1

If the view doesn't show, go to Window -> Perspective -> Reset Perspective..

Upvotes: 0

user939857
user939857

Reputation: 395

I get this problem from time to time.

There is something corrupted in the eclipse workspace.

The only solution for me is to create a new workspace and bring in the projects.

It's a serious pain when there are fifty projects in the workspace.

Upvotes: 0

Matthew Farwell
Matthew Farwell

Reputation: 61705

You can't interact with the JUnit view from your code using JUnitCore.

You can however, add your tests to the JUnitView if you use a @Parameterized test, or if you implement your own test runner. Try extending the Suite class and reimplement one of the constructors with the tests that you want to execute.

Upvotes: 0

mki
mki

Reputation: 635

I suppose you run your code in the main method like this example :

public class MiniTest extends TestCase
{
@Test
public void test()
{
    System.out.println("Running test");
}

public static void main(String[] args)
{
    JUnitCore core = new JUnitCore();
    core.run(MiniTest.class);
}

In this case, it will not show your view because you launch your program as a java application (alt-shift-X-J). You will see "Running test" in the console but that is.
If you want to see the Junit View you must launch your program as a Junit test (alt-shit-X-T).
Note that with this manner the main() is not necessary, Eclipse will directly launch the method tagged with @Test. You can also group tests with @Suite.

Upvotes: 0

Anurag Tripathi
Anurag Tripathi

Reputation: 1208

On your toolbar click Windows-->Show View-->Others. Type "Junit" without quotes. Select from list and click OK.

Upvotes: 12

Related Questions