@Test单元测试配置

两种的区别:测试的位置不一样

第一种:

在这里插入图片描述

       <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-test</artifactId>
          <scope>test</scope>
        </dependency>
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBootApplicationTests {
 
    @Autowired
    private UserService userService;
 
    @Test
    public void testAddUser() {
      
    }
 
}

第二种

<!--单元测试的依赖-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>

public class Test {
    @Test
    public void test(){
        System.out.println("JUnit单元测试");
    }
}



第二种 扩展

子服务

 <dependencies>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<scope>test</scope>
		</dependency>

		<!-- junit -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<resources>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.properties</include>
					<include>**/*.xml</include>
				</includes>
				<filtering>false</filtering>
			</resource>
		</resources>
	</build>

父项目

<!-- Junit 5 -->
		<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-test</artifactId>
				<version>5.1.8.RELEASE</version>
				<!--version>${spring.version}</version-->
				<!-- <scope>runtime</scope> -->
			</dependency>



			<dependency>
				<groupId>org.junit.jupiter</groupId>
				<artifactId>junit-jupiter-api</artifactId>
				<version>${junit.jupiter.version}</version>
				<scope>test</scope>
			</dependency>
			<dependency>
				<groupId>org.junit.jupiter</groupId>
				<artifactId>junit-jupiter-engine</artifactId>
				<version>${junit.jupiter.version}</version>
				<scope>test</scope>
			</dependency>

			<dependency>
				<groupId>org.junit.vintage</groupId>
				<artifactId>junit-vintage-engine</artifactId>
				<version>${junit.jupiter.version}</version>
				<scope>test</scope>
			</dependency>

			<dependency>
				<groupId>org.junit.platform</groupId>
				<artifactId>junit-platform-launcher</artifactId>
				<version>${junit.platform.version}</version>
				<scope>test</scope>
			</dependency>

			<dependency>
				<groupId>org.junit.platform</groupId>
				<artifactId>junit-platform-runner</artifactId>
				<version>${junit.platform.version}</version>
				<scope>test</scope>
			</dependency>
			<!-- Junit 5 End -->
		</dependencies>
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class JosionMapperTest {

    private SqlSession sqlSession;
    private JosionUserMapper mapper;

    @Before
    public void setUp() throws Exception {
        System.out.println("#setUp start...");
        sqlSession = MybatisUtil.getSession();
        mapper = sqlSession.getMapper(JosionUserMapper.class);
    }

    @After
    public void tearDown() throws Exception {
        System.out.println("#tearDown start...");
        sqlSession.commit();
        MybatisUtil.closeSession();
    }

//    @Test
    public void maxId() {
    	JosionUserQO qo = new JosionUserQO();
    	qo.setTableName("T_USER0");
    	try {
    		Integer in = mapper.maxId();
    		System.out.println(in);
    	}catch(Exception e) {
    		System.out.println(e);
    	}
    }
QS:第一种好像包含第二种
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值