Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
head_group
xyqb-user2
Commits
58a0064f
Commit
58a0064f
authored
Jan 10, 2018
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化测试用例
parent
035ef7f7
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
26 additions
and
33 deletions
+26
-33
BaseParametersTests.java
src/test/java/demo/BaseParametersTests.java
+2
-1
MockMvcTests.java
src/test/java/demo/MockMvcTests.java
+3
-4
MvcTests.java
src/test/java/demo/MvcTests.java
+3
-4
ParametersJunit5Tests.java
src/test/java/demo/ParametersJunit5Tests.java
+0
-1
RepsitoryJpaTests.java
src/test/java/demo/RepsitoryJpaTests.java
+3
-5
RepsitoryTests.java
src/test/java/demo/RepsitoryTests.java
+2
-3
ServiceTests.java
src/test/java/demo/ServiceTests.java
+2
-3
WebTests.java
src/test/java/demo/WebTests.java
+5
-4
TestUserLogin.java
src/test/java/login/TestUserLogin.java
+3
-3
TestUserService.java
src/test/java/service/TestUserService.java
+3
-5
No files found.
src/test/java/demo/BaseParametersTests.java
View file @
58a0064f
...
...
@@ -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
;
...
...
src/test/java/demo/MockMvcTests.java
View file @
58a0064f
...
...
@@ -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
;
...
...
src/test/java/demo/MvcTests.java
View file @
58a0064f
...
...
@@ -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
...
...
src/test/java/demo/ParametersJunit5Tests.java
View file @
58a0064f
...
...
@@ -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
)
{
...
...
src/test/java/demo/RepsitoryJpaTests.java
View file @
58a0064f
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
)
...
...
src/test/java/demo/RepsitoryTests.java
View file @
58a0064f
...
...
@@ -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
...
...
src/test/java/demo/ServiceTests.java
View file @
58a0064f
...
...
@@ -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
...
...
src/test/java/demo/WebTests.java
View file @
58a0064f
...
...
@@ -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
()
);
}
}
...
...
src/test/java/login/TestUserLogin.java
View file @
58a0064f
...
...
@@ -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
...
...
src/test/java/service/TestUserService.java
View file @
58a0064f
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment