In Junit not able to run the test cases sequentially. | Selenium Forum
M
Posted on 26/12/2015
Following code not generating the output sequentially.It skipped first test case logintest but it executed in last.Please help me why this happening.Annotation also added part of testcase name eventhough it is not executed sequentially

[b:gmnadng1][u:gmnadng1]Code[/u:gmnadng1][/b:gmnadng1]
package Test1;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class Test2 {

@Before
public void browsercheck()
{
System.out.println("Browser Opened");
}


@Test
public void LoginTest()
{
System.out.println("Login to the application");
}

@Test
public void RegisterTest()
{
System.out.println("Registering");
}

@Test
public void logoutTest()
{
System.out.println("Logout from application");
}

@After
public void browserclose()
{
System.out.println("browser Closed");
}

}

[b:gmnadng1][u:gmnadng1]Output:[/u:gmnadng1][/b:gmnadng1]
Browser Opened
Registering
browser Closed
Browser Opened
Logout from application
browser Closed
Browser Opened
Login to the application
browser Closed

M
Replied on 27/12/2015

do you want

[color=#FF0000:10z50oxx]Browser Opened
Registering
Login to the application
Logout from application
browser Closed
[/color:10z50oxx]


M
Replied on 28/12/2015

Login to application result should come first then registering,logout from application

[u:w1y1jth6]Expected Result:[/u:w1y1jth6]

Browser Opened
Registering
browser Closed
Browser Opened
Logout from application
browser Closed
Browser Opened
[i:w1y1jth6][u:w1y1jth6][b:w1y1jth6][color=#FF0040:w1y1jth6]Login to the application[/color:w1y1jth6][/b:w1y1jth6][/u:w1y1jth6][/i:w1y1jth6]
browser Closed


M
Replied on 28/12/2015

You should never write tests that need to be executed in a specified order. That's really bad practice. Every test should be able to run independent.

see this q/a for more info

http://stackoverflow.com/questions/3693626/how-to-run-test-methods-in-specific-order-in-junit4