dimanche 12 juillet 2015

how to unit test code that should cause compile error

I have a class that take a ArrayList as parameter:

public class Foo {
    private ArrayList<Bar> bars;

    public Foo(ArrayList barList) {
        bars = barList;
    }
}

there is a bug that I can pass any ArrayList into the constructor:

// should compile error with this line
Foo foo = new Foo(new ArrayList<String>());

the problem is if I add this case to test suite, when the bug fixed, I can not compile it. is there anyway to test this case?

Aucun commentaire:

Enregistrer un commentaire