Spring 下使用Junit4 單元測試
阿新 • • 發佈:2019-04-29
frame ring pat public pre tin port ppc java
package platform; import java.util.List; import java.util.UUID; import javax.annotation.Resource; import org.apache.commons.codec.digest.DigestUtils; 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 org.springframework.test.context.web.WebAppConfiguration; import com.xxx.xxx.model.ProjectInfo; import com.xxx.xxx.service.ProjectInfoService; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations= {"classpath:applicationContext.xml"}) @WebAppConfiguration public class JunitTest { // @Resource @Autowired private ProjectInfoService projectInfoService; @Test public void demo2(){ ProjectInfo projectInfo = projectInfoService.findProjectInfoById("ID"); System.out.println(projectInfo.getName()); } }
不寫單元測試的程序員不是好程序員。
Spring 下使用Junit4 單元測試