import org.junit.Test; import static org.junit.Assert.*; public class MyLibraryTest { @Test public void testAddition() { int result = MyLibrary.add(2, 3); assertEquals(5, result); } @Test public void testSubtraction() { int result = MyLibrary.subtract(5, 2); assertEquals(3, result); } } import org.junit.Test; import static org.mockito.Mockito.*; public class MyLibraryTest { @Test public void testDependency() { Dependency mockDependency = mock(Dependency.class); when(mockDependency.doSomething()).thenReturn("mocked result"); MyLibrary myLibrary = new MyLibrary(mockDependency); String result = myLibrary.someMethodUsingDependency(); verify(mockDependency).doSomething(); assertEquals("mocked result", result); } }


上一篇:
下一篇:
切换中文