???????Service???mockito
???????????? ???????[ 2015/7/17 13:34:02 ] ???????????????
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
????1??maven?????
<!-- mockito -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<!-- junit 4 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
????2????????service??@InjectMocks???service??????@Mock???
????@InjectMocks
????@Autowired
????private TestService testService;
????@Mock
????private TestMapper testMapper;
????3????@Before?????mock
????@Before
????public void init() throws Exception {
????MockitoAnnotations.initMocks(this);
????}
????4?????????
????when(testMapper.getTestList()).thenReturn(list1);
????List<TestInfo> list = testService.getTestList();
????assertEquals("bname"?? list.get(0).getTest_name());
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11