标签:code group div als loser ica contex test col
增加maven依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
HelloService.java
package com.zns.service; import org.springframework.stereotype.Service; @Service public class HelloService { public String getName(){ return"hello"; } }
HelloServiceTest.java
package com.zns.test; import javax.annotation.Resource; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.zns.MyApplication; import com.zns.service.HelloService; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = MyApplication.class) public class HelloServiceTest { @Resource private HelloService helloService; @Test public void testGetName() { Assert.assertEquals("hello", helloService.getName()); } }
这时候就可以进行测试了,右键—RunAs – Junit Test。
标签:code group div als loser ica contex test col
原文地址:https://www.cnblogs.com/zengnansheng/p/10389795.html