Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Tests not executing in specified order(Tests written inside a class are not being executed in order.)
Tests not executing in specified order [message #553313] Tue, 17 August 2010 07:03 Go to next message
Anitha Mising name is currently offline Anitha Mising nameFriend
Messages: 28
Registered: February 2010
Junior Member
i have couple of test cases which are dependant on each other. However the tests mentioned inside the same class are not getting executed in the order specified in the class.

For example, i have a class say

TestPerspective {
@Test
public void testMenu1() {}
public void testMenu2() {}
public void testMenu3() {}
}

Now i would expect the test cases to run in the below order:
testMenu1()
testMenu2()
testMenu3()

However they run as
testMenu3()
testMenu1()
testMenu2()

How can i make them run in the order specified?
Re: Tests not executing in specified order [message #553422 is a reply to message #553313] Tue, 17 August 2010 13:27 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
On 10-08-17 03:03 AM, Anitha wrote:
> i have couple of test cases which are dependant on each other. However
> the tests mentioned inside the same class are not getting executed in
> the order specified in the class.
> For example, i have a class say
> TestPerspective {
> @Test
> public void testMenu1() {}
> public void testMenu2() {}
> public void testMenu3() {}
> }
>
> Now i would expect the test cases to run in the below order:
> testMenu1()
> testMenu2()
> testMenu3()
>
> However they run as testMenu3()
> testMenu1()
> testMenu2()
>
> How can i make them run in the order specified?

Unfortunately, you can't... this is just impossible with JUnit. But, in
my experience, if you have tests that depends on each other, it is a
sign the your test suite have a problem. It is generally a bad pattern
to make tests depends on each other, since it can result on some weird
behavior sometimes. I might not be the best person to explain the
concept of test independence and all that is related, but as a rule of
thumb I try to avoid this kind of thing.

I also know that if testMenu1() does some general things, such as
setting some fields or creating some resources, you might want to use a
@Before method: it will be executed before every test you run. You would
also need an @After method to do some clean-up, because such a method
gets executed after each test you run. There is also @BeforeClass and
@AfterClass, which gets executed once for the whole test class. So let's
say you have:

TestPerspective {
@Test
public void testMenu1() {}
@Test
public void testMenu2() {}
@Test
public void testMenu3() {}
@Before
public void before() {}
@After
public void after() {}
@BeforeClass
public static void createResources() {}
@AfterClass
public static void deleteResources() {}
}

you'll get the execution:

createResources()
before()
one of the test method
after()
before()
another test method
after()
.... snip ...
before()
last test method
after()
deleteResources()

Look for the javadoc of those annotations for more in-depth explanation.

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Tests not executing in specified order [message #555888 is a reply to message #553422] Mon, 30 August 2010 04:32 Go to previous messageGo to next message
Anitha Mising name is currently offline Anitha Mising nameFriend
Messages: 28
Registered: February 2010
Junior Member
Thanks for your information. I knew we can't do it with JUnit. I was just wondering if SWTBot was somehow able to workaround to get this working as unlike JUnit, SWTBot is a GUI based functional testing framework.

I cannot use @before and @After as the settings for each test case is not the same. I had to rewrite all my test cases to perform all the setups and then perform the test for each test case.

Thanks once again.
Re: Tests not executing in specified order [message #555939 is a reply to message #555888] Mon, 30 August 2010 10:12 Go to previous message
speedracer  is currently offline speedracer Friend
Messages: 19
Registered: August 2009
Junior Member
If you run your Tests with the SWTBotJunit4ClassRunner. Then the test run in alphabetical order. That means you must only change the name of the test methods in a testclass and your test methodes run in the order you need.
Previous Topic:Setting keyboard layout different to the system's default
Next Topic:MultiPageEditor with Tabs(GEF Editor) and SWTBot
Goto Forum:
  


Current Time: Fri Apr 19 00:39:42 GMT 2024

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

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

Back to the top