如图 看尚硅谷的Java视频的时候看到他经常选择某一个函数然后右键就能运行那个函数 而我自己在idea上试的时候只能运行main函数 有大佬知道这个怎么弄的吗
<!--junit-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
导入Maven坐标,或则导入jar包依赖
直接像图片上那样加@Test注解,报错的话让idea帮你解决,idea会自动导入需要的单元测试依赖的。
<!-- SpringBoot 测试起步依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
首先引入这个
然后找到test,没有就自己创建
最后创建java文件,在类的头上加 @SpringBootTest,方法上面加@Test
这是单元测试,@Test 你看这个注解
你网上搜一下 junit test 教程,就知道怎么回事了,单元测试
<!--junit--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency>