As i know, good convention for writing unit&integration tests is that for each testable class should be created one test class. Given that i need to test three methods of Testable class and provide several sets of data for each test of method
public class Testable {
public void doSmth1(A param1, B param2, C param3){}
public void doSmth2(D param1, E param2){}
public void doSmth3(E param1){}
}
I know, that i can use Parametrized.class runner and provide data for test:
@RunWith(Parameterized.class)
@SmallTest
class TestableTest {
@Parameterized.Parameters
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{new A(1), new B(1), new C(1)},
{new A(2), new B(2), new C(2)},
});
}
private A a;
private B b;
private C c;
public TestableTest(A a, B b, C c) {
this.a = a;
this.b = b;
this.c = c;
}
@Test
public void testSmth() {
//this test will run for each set of @Parameters and i'm able to test doSmth1 method
}
}
But like that i'm able to test only one method in this class and no more, because them use data set of another types at all.
How can i achieve this goal and test all three methods in one class? Is it possible for android tests?
I know that there are several libraries for clean java unit tests like [JUnitParams][1] to achieve this, but not for android, unfortunately.
Ps: of cource, i understand that i can initialize data set in target set method and check it in for-loop, but such things don't make code flat and readable.
Aucun commentaire:
Enregistrer un commentaire