I am having a Java class A. A's constructor calls few methods m1,m2.
class A{
public A(){
m1();
m2();
...... }
public void m1(){...};
public void m2(){...};
}
How to write tests for these methods? I generally write them as
class TestClass{
static A a = null;
public TestClass(){
a = new A();
}
@Test
public testm1(){
A.m1();
//Some logic
}
However, these functions are called in the constructor itself. It looks like I am executing the method twice to check, and the constructor itself fails if the method is incorrectly written. What is the proper way of testing it?
Aucun commentaire:
Enregistrer un commentaire