Android的,JUnit和测试preconditions() [英] Android, Junit and testPreconditions()

查看:246
本文介绍了Android的,JUnit和测试preconditions()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做我的应用程序的数据库中获得一些测试。
我只有在我的应用程序(家)一个活动,所以我的测试类是结果
公共类HomeTest扩展ActivityInstrumentationTestCase2 {..}

我的烦恼:

1)在Android开发我见过的测试preconditions()方法应该是所有测试前推出,但在我的应用程序,它像一个正常的测试...

2)我希望所有其他测试开始之前,以填补我的数据库。但要做到这一点,我需要对我的活动的参考,但我不能在测试中构造函数中调用this.getActivity...
有没有办法做到的构造函数之后的东西吗?
(该设置()方法是不恰当的,因为它是在每次测试之前调用,而不是只是一个时间前全部)

感谢


解决方案

  1. 在测试运行的顺序为不保证之前其他的测试运行,因为JUnit 3使用反射来寻找测试。


  2. 使用设置()的方法,这也保证了你的测试,一个全新的数据库运行


I'm trying to do some tests on my application's database. I only got one activity in my application ("Home") so my test class is
public class HomeTest extends ActivityInstrumentationTestCase2 {..}

My troubles :

1) In Android developers I've seen that testPreconditions() method is supposed to be launch before all tests, but in my app, it's acting like a normal test ...

2) I'd like to fill my database before all other tests to begin. But to do so, I need a reference on my Activity, but I can't call "this.getActivity" in the tests constructor ... Is there a way to do something after the constructor ? (The setUp() method isn't appropriate, because it is called before each test, not just one time before all)

Thanks

解决方案

  1. The order in which the test are run is not guaranteed to run before other tests, as junit 3 uses reflection to find the tests.

  2. Use the setUp() method, this also assure that your tests run with a fresh database

这篇关于Android的,JUnit和测试preconditions()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆