Skip to content
zhangjie edited this page Aug 8, 2020 · 10 revisions

测试用例

pom文件引入jar包

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>4.3.2.RELEASE</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>

单元测试编写

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
                        "classpath:beans.xml",
                        "classpath:mybatis.xml"
                    })
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ServiceTest {
   @Resource
   private TrackService trackService;

   @Test
   public void testFindListByReferenceNo(){
       List<TrackEnt> list =  service.findListByReferenceNo("KKon0019998");
       assertEquals(10,list.size());
   }
}

1.1 通过@Before实现测试用例运行前初始化
1.2 通过@After实现测试用例完成后清理
1.3 参考:https://www.jianshu.com/p/83eadf7b352f

Clone this wiki locally