Commit 58a0064f authored by 技术部-任文超's avatar 技术部-任文超

优化测试用例

parent 035ef7f7
......@@ -4,7 +4,8 @@ import org.junit.Before;
import org.springframework.test.context.TestContextManager;
/**
* Created by xuran on 2017/12/26.
* @author renwc
* @date 2018-01-05
*/
public abstract class BaseParametersTests {
private TestContextManager testContextManager;
......
......@@ -7,14 +7,11 @@ import cn.quantgroup.xyqb.controller.internal.user.UserController;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.service.user.IUserService;
import com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer;
import jdk.nashorn.internal.runtime.regexp.joni.Config;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
......@@ -23,6 +20,8 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import javax.annotation.Resource;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
......@@ -33,7 +32,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@WebMvcTest({UserController.class})
@ContextConfiguration(classes = {JpaConfig.class, RedisConfig.class}, initializers = ApolloPropertySourceInitializer.class)
public class MockMvcTests {
@Autowired
@Resource
private MockMvc mvc;
@MockBean
private IUserService userService;
......
......@@ -9,27 +9,26 @@ import 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.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import javax.annotation.Resource;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Bootstrap.class)
@ContextConfiguration(initializers = ApolloPropertySourceInitializer.class)
@WebAppConfiguration
public class MvcTests {
private MockMvc mvc;
@Autowired
@Resource
WebApplicationContext webApplicationConnect;
@Before
......
......@@ -30,7 +30,6 @@ public class ParametersJunit5Tests {
System.out.println("Not Ready to Run");
}
@Ignore("Not Ready to Run")
@DisplayName("My 1st JUnit 5 test! 😎")
@org.junit.jupiter.api.Test
public void myFirstTest(TestInfo testInfo) {
......
package demo;
import cn.quantgroup.xyqb.Bootstrap;
import cn.quantgroup.xyqb.config.data.JpaConfig;
import cn.quantgroup.xyqb.config.data.RedisConfig;
import cn.quantgroup.xyqb.entity.User;
......@@ -9,16 +8,15 @@ import com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.persistence.PersistenceException;
import java.sql.Timestamp;
import java.time.Instant;
......@@ -36,9 +34,9 @@ import java.time.Instant;
@AutoConfigureTestDatabase(replace= AutoConfigureTestDatabase.Replace.NONE)
public class RepsitoryJpaTests {
@Autowired
@Resource
private TestEntityManager entityManager;
@Autowired
@Resource
private IUserRepository userRepository;
@Test(expected = PersistenceException.class)
......
......@@ -7,14 +7,13 @@ import com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.PersistenceException;
import javax.annotation.Resource;
import java.sql.Timestamp;
import java.time.Instant;
......@@ -31,7 +30,7 @@ import java.time.Instant;
@ContextConfiguration(initializers = ApolloPropertySourceInitializer.class)
public class RepsitoryTests {
@Autowired
@Resource
private IUserRepository userRepository;
@Test
......
......@@ -7,14 +7,13 @@ import com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.PersistenceException;
import javax.annotation.Resource;
import java.sql.Timestamp;
import java.time.Instant;
......@@ -30,7 +29,7 @@ import java.time.Instant;
@ContextConfiguration(initializers = ApolloPropertySourceInitializer.class)
public class ServiceTests {
@Autowired
@Resource
private IUserService userService;
@Test
......
......@@ -6,7 +6,6 @@ import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
......@@ -15,6 +14,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* 控制层测试用例
......@@ -27,7 +28,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@ContextConfiguration(initializers = ApolloPropertySourceInitializer.class)
public class WebTests {
@Autowired
@Resource
private TestRestTemplate restTemplate;
@Test
......@@ -37,8 +38,8 @@ public class WebTests {
@Test
public void test() {
ResponseEntity<String> phil = restTemplate.getForEntity("/{model}/list", String.class, "log");
Assert.assertEquals(phil.getStatusCode(), HttpStatus.OK);
ResponseEntity<String> phil = restTemplate.getForEntity("/{model}/test", String.class, "user");
Assert.assertEquals(HttpStatus.OK, phil.getStatusCode());
}
}
......
......@@ -19,12 +19,12 @@ import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
......@@ -39,10 +39,10 @@ public class TestUserLogin {
private MockHttpServletRequest request = new MockHttpServletRequest();;
@Autowired
@Resource
private UserController userController;
@Autowired
@Resource
private InnerController innerController;
@Test
......
......@@ -4,7 +4,6 @@ import cn.quantgroup.xyqb.Bootstrap;
import cn.quantgroup.xyqb.entity.Address;
import cn.quantgroup.xyqb.service.user.IAddressService;
import cn.quantgroup.xyqb.service.user.IContactService;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
......@@ -12,14 +11,13 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestContextManager;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Arrays;
......@@ -39,9 +37,9 @@ public class TestUserService {
private TestContextManager testContextManager;
@Autowired
@Resource
private IAddressService addressService;
@Autowired
@Resource
private IContactService contactService;
private Address addressObj;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment