android:junit 运行参数化测试用例
我想运行具有不同参数的单个测试用例。 在java中 可以通过junit4实现,代码如下
package com.android.test;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ParameterizedTestExample {
private int number;
private int number2;
private int result;
private functioncall coun;
//constructor takes parameters from array
public ParameterizedTestExample(int number, int number2,
int result1) {
this.number = number;
this.number2 = number2;
this.result = result1;
coun = new functioncall();
}
//array with parameters
@Parameters
public static Collection<Object[]> data() {
Object[][] data = new Object[][] { { 1, 4, 5 }, { 2, 7, 9 },
{ 3, 7, 10 }, { 4, 9, 13 } };
return Arrays.asList(data);
}
//running our test
@Test
public void testCounter() {
assertEquals("Result add x y", result, coun.calculateSum(this.number, this.number2), 0);
}
}
现在我的问题是我们可以在处理上下文的android测试用例中运行相同的操作吗?
当我尝试使用 android junit 运行代码时。 它给我错误NoClassDefinationFound。
i wan to run a single testcase with different parameters.
in java
it possible through junit4 and code is like this
package com.android.test;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ParameterizedTestExample {
private int number;
private int number2;
private int result;
private functioncall coun;
//constructor takes parameters from array
public ParameterizedTestExample(int number, int number2,
int result1) {
this.number = number;
this.number2 = number2;
this.result = result1;
coun = new functioncall();
}
//array with parameters
@Parameters
public static Collection<Object[]> data() {
Object[][] data = new Object[][] { { 1, 4, 5 }, { 2, 7, 9 },
{ 3, 7, 10 }, { 4, 9, 13 } };
return Arrays.asList(data);
}
//running our test
@Test
public void testCounter() {
assertEquals("Result add x y", result, coun.calculateSum(this.number, this.number2), 0);
}
}
Now my question is can we Run the same with android testcases where we have deal with context.
when i try to run the code using android junit.
it gives me error NoClassDefinationFound.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论