@ExtendWith(value = {MockitoExtension.class}) @RunWith(JUnitPlatform.class) class MyTest { @Test void test1() throws IOException { new MockUp<System>() { @mockit.Mock public String getProperty(String key){ return "abc"; } }; assertThat(System.getProperty("a"), is("abc")); } @Test void test2() throws IOException { System.out.println(System.getProperty("a")); //Prints abc } }
Sunday, 25 August 2019
Static method MockUp effect is global
Use mockit.MockUp.MockUp() to mock public static methods. One caveat is that the mocked behaviour applies to other test methods as well. (test2() prints "abc", which is surprising, isn't it?)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment