1.pom.xml中加入
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.3.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>4.3.0.RELEASE</version> </dependency>
2.测试代码
package com.hshbic.cloudapp.thirdserver; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hshbic.cloudapp.thirdserver.service.StatusDataPushService; @RunWith(value = SpringJUnit4ClassRunner.class) @ContextConfiguration({"classpath:spring/*.xml"}) public class JunitTest { @Autowired public StatusDataPushService service ; @Before public void setUp() throws Exception { } @Test public void testGetSign() throws Exception { String sign=""; sign=service.getSign("SV-RAIN001815-0000","938233258bd0b8aad67d2a5cdfe5bac1","20180710172055"); assertEquals("022729426af392e69df55445c141025533e64f7d7aeee9c1327d7688bafe1d71", sign); } }