0

I have a parametric test class, and I have a test method which I am expected to return IllegalArgumentException.

@RunWith(value = Parameterized.class)
public class TriangleParametrizedTest {

    @Rule
    public ExpectedException exception = ExpectedException.none();

    enum Type {
        EQUILATERAL,
        NEGETIVE
    };

    private Type type;

    private int sideA;
    private int sideB;
    private int sideC;

    public TriangleParametrizedTest(Type type, int sideA, int sideB, int sideC) {
        this.type = type;
        this.sideA = sideA;
        this.sideB = sideB;
        this.sideC = sideC;
    }

    @Parameters()
    public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][]{
            {Type.EQUILATERAL, 5, 5, 5},
            {Type.NEGETIVE, -5, 5, 5},});
    }

    @Test()
    public void negetiveSideTest() {
        Assume.assumeTrue(type == Type.NEGETIVE);
        exception.expect(IllegalArgumentException.class);
        Triangle trianle = new Triangle(sideA, sideB, sideC);

    }

}

but I have got this error : INitialization error : no test found matching Method negetiveSideTest ..

has anybody any solution?

Azin
  • 21
  • 3

1 Answers1

0

When you use the @Test annotation to mark your test function, there should be no parenthesis, like so:

@Test   <--- Remove the parenthesis here
public void negetiveSideTest() {
    Assume.assumeTrue(type == Type.NEGETIVE);
    exception.expect(IllegalArgumentException.class);
    Triangle trianle = new Triangle(sideA, sideB, sideC);
}

Same goes for your @Parameters declaraion.

hopia
  • 4,880
  • 7
  • 32
  • 54