Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Test and Performance Tools Platform (TPTP) » Running JUnit 4 tests organised with inner classes
Running JUnit 4 tests organised with inner classes [message #788050] Wed, 01 February 2012 09:38 Go to next message
Joe Lemmer is currently offline Joe LemmerFriend
Messages: 2
Registered: February 2012
Junior Member
Hi,

I have organised my JUnit tests using one test class for the class that I'm testing and one static inner class each for each method / behaviour that I'm testing.

public class TestMyClass {

    public static class TestMyFirstMethod {
        
        @Test
        public void testMthodOneDoesSomething() {
            // test code here
        }

        @Test
        public void testMethodOneDoesSomethingElse() {
            // test code here
        }
    }

    public static class TestMyMethodTwo {
  
        @Test
        public void testMyMthodTwoDoesSomething() {
            // test code here
        }
    }
}


This works really well for me from an organisational point of view, but I'm am having trouble finding out how to run all the scripts at once. When I shift+alt+X T to run the tests, Eclipse offers me a choice of all the inner classes to run and I seem to have to pick one rather than to run all of them at once.

I really want to run them all at the same time. Is there a way I can configure this?

Many thanks
Re: Running JUnit 4 tests organised with inner classes [message #788074 is a reply to message #788050] Wed, 01 February 2012 10:16 Go to previous messageGo to next message
Heiner Westphal is currently offline Heiner WestphalFriend
Messages: 18
Registered: July 2009
Junior Member
Hello Joe,

JUnit 4 comes with a runner class called Enclosed, which does what you need.

Annotate the outer class with
@RunWith(Enclosed.class)
with Enclosed =
import org.junit.experimental.runners.Enclosed;

and you should be fine.

Hope this helps,

Heiner


Am 01.02.2012 10:38, schrieb Joe Lemmer:
> Hi,
>
> I have organised my JUnit tests using one test class for the class that
> I'm testing and one static inner class each for each method / behaviour
> that I'm testing.
>
> public class TestMyClass {
>
> public static class TestMyFirstMethod {
> @Test
> public void testMthodOneDoesSomething() {
> // test code here
> }
>
> @Test
> public void testMethodOneDoesSomethingElse() {
> // test code here
> }
> }
>
> public static class TestMyMethodTwo {
>
> @Test
> public void testMyMthodTwoDoesSomething() {
> // test code here
> }
> }
> }
>
> This works really well for me from an organisational point of view, but
> I'm am having trouble finding out how to run all the scripts at once.
> When I shift+alt+X T to run the tests, Eclipse offers me a choice of all
> the inner classes to run and I seem to have to pick one rather than to
> run all of them at once.
>
> I really want to run them all at the same time. Is there a way I can
> configure this?
>
> Many thanks
Re: Running JUnit 4 tests organised with inner classes [message #788105 is a reply to message #788074] Wed, 01 February 2012 10:56 Go to previous message
Joe Lemmer is currently offline Joe LemmerFriend
Messages: 2
Registered: February 2012
Junior Member
Heiner, thanks very much for your help. That was exactly what I wanted.
Previous Topic:Eclipse Java Testing Tools - JAVA SE and JSP
Next Topic:No Profiling data captured, whatsoever.
Goto Forum:
  


Current Time: Thu Apr 25 15:50:41 GMT 2024

Powered by FUDForum. Page generated in 0.02684 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top