lundi 26 août 2019

Mock setter for the method where only getter exist using PoweMockRunner

I create a test method for very simple part of code. There was only a getter method which should return a String message. But when I run the test code and I have this error: No instance field named "getMessage" could be found

In my base class I don't have a setter for this field (message) I have only getter(getMessage) so I use PoweMockRunner to set a mock setter for this message field

public class HelloWorldModel {
private String message;

public String getMessage() {
        return message;
    }
}

and this is My test code:

  @Test
    public void checkGetMessage(){
        HelloWorldModel helloWorldModel = new HelloWorldModel();
        Whitebox.setInternalState(helloWorldModel, "message", "test");
        Assert.assertEquals("", (String) helloWorldModel.getMessage());

    }

I have an information that test failed and: Expected : Actual :test

Aucun commentaire:

Enregistrer un commentaire