Reputation: 1481
How we would save our Test results in object after that test finished in success/failure status. I need the result data like date/time of started test, time elapsed and etc.
any idea?
Upvotes: 1
Views: 2411
Reputation: 606
You can export your tests results using "Export Test Results" option to .html, or .xml file.
If that's not enough, then look at the android test output console. You can copy-paste the commands and create your own script using e.g. powershell, or anything you want. Also check this link
edit:
Ahh, sorry I think I didn't read properly. You want to catch the result as a object in code after every test? So.. you can't use @after
- your function can't takes any parameters. By using TestWatcher you can get Description
object, but I don't saw the informations about test time. But if you calculate time in your own..
@RunWith(AndroidJUnit4.class)
public class TestClass {
private long startTime;
@Rule
public TestRule watcher = new TestWatcher() {
@Override
protected void failed(Throwable e, Description description) {
long estimatedTime = System.currentTimeMillis() - startTime;
}
@Override
protected void succeeded(Description description) {
long estimatedTime = System.currentTimeMillis() - startTime;
}
};
@org.junit.Test
public void Test() {
startTime = System.currentTimeMillis();
//your test here
}
}
Hope it helps!
Upvotes: 1