【发布时间】:2015-07-08 18:48:42
【问题描述】:
我使用 Eclipse 编写了一个主要使用 GPS 的 android 应用程序。
我想为应用程序进行JUNIT 测试。
为我的单元测试指定多个值的最佳方法是什么?
【问题讨论】:
标签: android eclipse unit-testing testing junit
我使用 Eclipse 编写了一个主要使用 GPS 的 android 应用程序。
我想为应用程序进行JUNIT 测试。
为我的单元测试指定多个值的最佳方法是什么?
【问题讨论】:
标签: android eclipse unit-testing testing junit
在每个测试中,您应该使用许多可用断言http://junit.org/apidocs/org/junit/Assert.html 之一来检查测试方法返回的值是否正确。在测试方法时,您可以将所需的任何参数传递给它。
例如
assertEquals("OK",myObj.methodUnderTest(param1,param2,param3));
【讨论】:
也许我误解了这个问题,但听起来你想要参数化测试。这允许您编写一个测试,但针对该测试测试几个不同的值。
我更熟悉 NUnit 的参数化单元测试,但 here's a link 对 JUnit 的参数化单元测试文档更熟悉。
【讨论】: