خرید بک لینک

Vote count: 0

I'm attempting to write some unit tests for an app of mine to verify that my class under test is utilizing the app's configured properties.

We're using OWNER (http://owner.aeonbits.org/) for our properties resolution, and JMockit (http://jmockit.org/) for our mocking framework.

My class to be tested:

public class TestMe {
    private final MyAppConfig config = ConfigFactory.create(MyAppConfig.class);

    public void doStuff() {
        String someValue = config.getSomeValue();
        ...
    }
}

and my test class:

public class TestMeTest {
    @Tested
    TestMe testMe;

    @Test
    public void doStuffShouldUseTheConfiguredSomeValue(@Mocked ConfigFactory configFactory, @Mocked MyAppConfig myAppConfig) {
        new Expectations() {{
            ConfigFactory.create(MyApp.class); result = myAppConfig;
            myAppConfig.getSomeValue(); result = "foo";
        }};

        testMe.doStuff();

        new Verifications() {{
            myAppConfig.getSomeValue(); times = 1;
        }};
    }
}

When I run the test, however, my mock instance of myAppConfig doesn't get called.

Can someone provide an example of the proper way to mock an OWNER Config object?

asked 35 secs ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 26 فروردين 1396 ساعت: 7:29

صفحه بندی