mercredi 27 janvier 2016

Use mock object in test method implementation

I have a question. There's a method with implementation using another objects. I'd like to test this method which will not using another objects invoking.

class Object1 {

    public void method1() {
        Object2 object2 = new Object2();
        String info = object2.getInfo();
        // ...
        // working with info, which I want to test
        // ...
    }

}

class Object1Test {
    @Test
    public void testMethod1() {
        Object1 object1 = new Object1();
        object1.method(); // want to run this method without invoking Object2
    }
}

Could you help me to understand how in junit can I mock the using Object2 with something like Object2Mock?

Aucun commentaire:

Enregistrer un commentaire