Issue
I would like to test one use case (scenario) of my android application. It should simulate user usage of app. Is it better to write one test method with code testing whole use case or should I create seperated methods for every part (in that case, test has to go in particular order)?
Example:
public void test() {
//click or button (open new activity)
//check if activity is opened
//open firm selection (open new activity)
....
}
or
public void test1(){
//click or button (open new activity)
//check if activity is opened
}
public void test2(){
//open firm selection (open new activity)
}
...
public void testX(){
//file at the end is created
}
What is the better approach and why?
Solution
What you seems to write looks like an UI user scenario test.
Strictly speaking, that is not an unit test, so you should not try to split artificially the processings in distinct test methods.
Doing it would be an error because each test method updates the state of the application and may rely on changes done by the previous tests. You get coupled tests that have to play in a specific order and a change in the first one have consequences on the others.
For example, the third executed test can fail because of the first one or the second one or the chaining of both. How to guess such a thing ?
So defining a single test method by distinct user story/ use case instance seems really the way and makes things clearer.
The basic Espresso example on their website goes in this way :
@Test
public void greeterSaysHello() {
onView(withId(R.id.name_field)).perform(typeText("Steve"));
onView(withId(R.id.greet_button)).perform(click());
onView(withText("Hello Steve!")).check(matches(isDisplayed()));
}
Answered By - davidxxx
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.