给若依添加单元测试
方案一(简单)
方案二(异常困难但企业开发一般用这个)
在 activity 子模块中添加单元测试
S1.在 src 目录下创建 test.java.MapperTests 文件
S2.将以下内容复制进去
importcom.ruoyi.activity.ActivityApplication;importcom.ruoyi.activity.domain.Activity;importcom.ruoyi.activity.mapper.ActivityMapper;importorg.junit.Test;importorg.junit.runner.RunWith;importorg.mybatis.spring.annotation.MapperScan;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.boot.test.context.SpringBootTest;importorg.springframework.test.context.junit4.SpringRunner;importjava.util.ArrayList;importjava.util.List;@RunWith(SpringRunner.class)@SpringBootTest(classes =ActivityApplication.class)@MapperScan(basePackages ="com.ruoyi.activity.mapper")publicclassMapperTests{@AutowiredprivateActivityMapper activityMapper;@TestpublicvoidtestSelectActivityById(){Activity activity = activityMapper.selectActivityById(1);System.out.println(activity);}@TestpublicvoidtestSelectActivityList(){List<Activity> activityList = activityMapper.selectActivityList(newActivity());System.out.println(activityList);}}
S3.将以下内容添加到 admin 的 pom.xml 中
<!-- Mysql驱动包 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><!-- 阿里数据库连接池 --><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId></dependency><!-- SpringBoot Web容器 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- 测试所需 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency>
S4.在 ActivityMapper 前添加 Mapper 注解
S5.在 activity 包下创建 ActivityApplication
S6.添加如下内容
packagecom.ruoyi.activity;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;importorg.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;/**
* 启动程序
*
* @author qiheng
*/@SpringBootApplication(exclude ={DataSourceAutoConfiguration.class})publicclassActivityApplication{publicstaticvoidmain(String[] args){// System.setProperty("spring.devtools.restart.enabled", "false");SpringApplication.run(ActivityApplication.class, args);System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n"+" .-------. ____ __ \n"+" | _ _ \\ \\ \\ / / \n"+" | ( ' ) | \\ _. / ' \n"+" |(_ o _) / _( )_ .' \n"+" | (_,_).' __ ___(_ o _)' \n"+" | |\\ \\ | || |(_,_)' \n"+" | | \\ `' /| `-' / \n"+" | | \\ / \\ / \n"+" ''-' `'-' `-..-' ");}}
S7.分别从 admin 和 framework 模块中将相关配置文件复制过来
终于成功了!
版权归原作者 苏黎世的民谣 所有, 如有侵权,请联系我们删除。