本指南將引導您完成基於Leopard Test模塊進行單元測試。java
你能夠從頭開始並完成每個步驟,或者您能夠繞過你已經熟悉的基本設置步驟。不管哪一種方式,你最終均可以獲得可工做的代碼。mysql
測試類只需繼承io.leopard.test.IntegrationTests基類,不須要爲測試作其餘任何配置.web
建立src/test/java/io/leopard/guides/dao/mysql/UserDaoMysqlImplTest.java
spring
package io.leopard.guides.dao.mysql; import io.leopard.burrow.lang.Json; import io.leopard.guides.model.User; import io.leopard.test.IntegrationTests; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; public class UserDaoMysqlImplTest extends IntegrationTests { @Autowired private UserDaoMysqlImpl userDaoMysqlImpl; @Test public void get() { User user = userDaoMysqlImpl.get(1L); Json.print(user, "user"); } }
建立src/test/java/io/leopard/guides/service/UserServiceTest.java
sql
package io.leopard.guides.service; import io.leopard.guides.model.User; import io.leopard.test.IntegrationTests; import java.util.Date; import org.junit.Assert; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; public class UserServiceTest extends IntegrationTests { @Autowired private UserService userService; @Test public void get() { this.userService.delete(1);// 先刪除記錄 { User user = new User(); user.setUid(1); user.setNickname("Leopard"); user.setPosttime(new Date()); userService.add(user); } { User user = userService.get(1); Assert.assertNotNull(user); Assert.assertEquals("Leopard", user.getNickname()); } } }
恭喜你!您已經學會在本地開發時如何使用Jetty容器作web測試,祝您好運.ide