How to select the order of which Test case to run in Eclipse android

How to select the order of which Test case to run in Eclipse android

here is my code :

ackage appium.learning;

import java.net.MalformedURLException;
import java.net.URL;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class LearningTest {

WebDriver driver;

@BeforeClass
public void setUp() throws MalformedURLException{
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("device", "Android");
    capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); //Name of mobile web browser to automate. Should be an empty string if automating an app instead.
    capabilities.setCapability(CapabilityType.VERSION, "4.4");
    capabilities.setCapability(CapabilityType.PLATFORM, "Android");
    capabilities.setCapability("app-package", "com.myapp"); //Replace with your app's package
    capabilities.setCapability("app-activity", ".myapp"); //Replace with app's Activity
    driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}




@AfterClass
public void tearDown(){
    driver.quit();
}


@Test
public void Cal1(){
    driver.findElement(By.name("1")).click();
}
@Test
public void Cal2(){
    driver.findElement(By.name("2")).click();
}
@Test
public void Cal3(){
    driver.findElement(By.name("3")).click();
}
Test
public void Cal4(){
    driver.findElement(By.name("4")).click();
}

}

I want them to run in order, lke, 1, 2, 3, 4

Thanks

Appium can’t help you much here. My best suggestion would be to do a google search for ‘ordering tests in junit’. Note that this is completely against the philosophy of junit (read their FAQ for more details, but loosely paraphrased, ‘test should be able to be run in an arbitrary order & not dependent on each other’) but there is this:

import org.junit.FixMethodOrder;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)

HTH. I encourage you to do a google search & read up about this.

@Wreed is correct, tests should be independent of each other.
You can achieve ordering with TestNG tool, Please refer http://goo.gl/VuK0Ni and http://goo.gl/vVS9wI .

Also can you explain why you need to run test cases in a specific order ?

I think wreed is correct but in a certain case we can have tests depend on the others.

For example, I have a flow including two steps in order: step1 and step2. And I have 2 test cases: one for step1 and one for the whole flow. So I would like to run the second test only if the first test is passed and in testNG they have attribute “dependsOnMethods” come a long with @Test annotation which allows you to define the running order.

I am not sure if junit has something like that though, you can look it up in their documents.