Android、Junit 和 testPreconditions()
我正在尝试对我的应用程序的数据库进行一些测试。 我的应用程序中只有一项活动(“Home”),所以我的测试类是
public class HomeTest extends ActivityInstrumentationTestCase2 {..}
我的麻烦:
1) 在 Android 开发人员中,我看到 testPreconditions() 方法应该在所有测试之前启动,但在我的应用程序中,它的行为就像正常测试一样......
2 )我想在所有其他测试开始之前填充我的数据库。但要做到这一点,我需要对我的 Activity 进行引用,但我无法在测试构造函数中调用“this.getActivity”... 有没有办法在构造函数之后做一些事情? (setUp()方法不合适,因为它在每次测试之前调用,而不是只调用一次)
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
测试运行的顺序不保证在其他测试之前运行,因为 junit 3 使用反射来查找测试。
使用
setUp()
方法,这也确保您的测试使用新的数据库运行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.
Use the
setUp()
method, this also assure that your tests run with a fresh database