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
79553c0b
Commit
79553c0b
authored
Dec 26, 2017
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
批量测试实例,jUnit5实例
parent
c800cf11
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
147 additions
and
6 deletions
+147
-6
DynamicTests.java
src/test/java/demo/DynamicTests.java
+115
-0
FirstTest.java
src/test/java/demo/FirstTest.java
+30
-0
OneTimeTokenTests.java
src/test/java/token/OneTimeTokenTests.java
+2
-6
No files found.
src/test/java/demo/DynamicTests.java
0 → 100644
View file @
79553c0b
package
demo
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
DynamicContainer
.
dynamicContainer
;
import
static
org
.
junit
.
jupiter
.
api
.
DynamicTest
.
dynamicTest
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Random
;
import
java.util.function.Function
;
import
java.util.stream.IntStream
;
import
java.util.stream.Stream
;
import
org.junit.jupiter.api.DynamicNode
;
import
org.junit.jupiter.api.DynamicTest
;
import
org.junit.jupiter.api.Tag
;
import
org.junit.jupiter.api.TestFactory
;
import
org.junit.jupiter.api.function.ThrowingConsumer
;
@Tag
(
"Test Factory"
)
public
class
DynamicTests
{
// This will result in a JUnitException!
@TestFactory
List
<
String
>
dynamicTestsWithInvalidReturnType
()
{
return
Arrays
.
asList
(
"Hello"
);
}
@TestFactory
Collection
<
DynamicTest
>
dynamicTestsFromCollection
()
{
return
Arrays
.
asList
(
dynamicTest
(
"1st dynamic test"
,
()
->
assertTrue
(
true
)),
dynamicTest
(
"2nd dynamic test"
,
()
->
assertEquals
(
4
,
2
*
2
))
);
}
@TestFactory
Iterable
<
DynamicTest
>
dynamicTestsFromIterable
()
{
return
Arrays
.
asList
(
dynamicTest
(
"3rd dynamic test"
,
()
->
assertTrue
(
true
)),
dynamicTest
(
"4th dynamic test"
,
()
->
assertEquals
(
4
,
2
*
2
))
);
}
@TestFactory
Iterator
<
DynamicTest
>
dynamicTestsFromIterator
()
{
return
Arrays
.
asList
(
dynamicTest
(
"5th dynamic test"
,
()
->
assertTrue
(
true
)),
dynamicTest
(
"6th dynamic test"
,
()
->
assertEquals
(
4
,
2
*
2
))
).
iterator
();
}
@TestFactory
Stream
<
DynamicTest
>
dynamicTestsFromStream
()
{
return
Stream
.
of
(
"A"
,
"B"
,
"C"
)
.
map
(
str
->
dynamicTest
(
"test"
+
str
,
()
->
{
/* ... */
}));
}
@TestFactory
Stream
<
DynamicTest
>
dynamicTestsFromIntStream
()
{
// Generates tests for the first 10 even integers.
return
IntStream
.
iterate
(
0
,
n
->
n
+
2
).
limit
(
10
)
.
mapToObj
(
n
->
dynamicTest
(
"test"
+
n
,
()
->
assertTrue
(
n
%
2
==
0
)));
}
@TestFactory
Stream
<
DynamicTest
>
generateRandomNumberOfTests
()
{
// Generates random positive integers between 0 and 100 until
// a number evenly divisible by 7 is encountered.
Iterator
<
Integer
>
inputGenerator
=
new
Iterator
<
Integer
>()
{
Random
random
=
new
Random
();
int
current
;
@Override
public
boolean
hasNext
()
{
current
=
random
.
nextInt
(
100
);
return
current
%
7
!=
0
;
}
@Override
public
Integer
next
()
{
return
current
;
}
};
// Generates display names like: input:5, input:37, input:85, etc.
Function
<
Integer
,
String
>
displayNameGenerator
=
(
input
)
->
"input:"
+
input
;
// Executes tests based on the current input value.
ThrowingConsumer
<
Integer
>
testExecutor
=
(
input
)
->
assertTrue
(
input
%
7
!=
0
);
// Returns a stream of dynamic tests.
return
DynamicTest
.
stream
(
inputGenerator
,
displayNameGenerator
,
testExecutor
);
}
@TestFactory
Stream
<
DynamicNode
>
dynamicTestsWithContainers
()
{
return
Stream
.
of
(
"A"
,
"B"
,
"C"
)
.
map
(
input
->
dynamicContainer
(
"Container "
+
input
,
Stream
.
of
(
dynamicTest
(
"not null"
,
()
->
assertNotNull
(
input
)),
dynamicContainer
(
"properties"
,
Stream
.
of
(
dynamicTest
(
"length > 0"
,
()
->
assertTrue
(
input
.
length
()
>
0
)),
dynamicTest
(
"not empty"
,
()
->
assertFalse
(
input
.
isEmpty
()))
))
)));
}
}
\ No newline at end of file
src/test/java/demo/FirstTest.java
0 → 100644
View file @
79553c0b
/*
* Copyright 2015-2016 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package
demo
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Tag
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.TestInfo
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
@Tag
(
"fast"
)
class
FirstTest
{
@Test
@DisplayName
(
"My 1st JUnit 5 test! 😎"
)
void
myFirstTest
(
TestInfo
testInfo
)
{
assertEquals
(
2
,
Math
.
addExact
(
1
,
1
),
"1 + 1 should equal 2"
);
assertEquals
(
"My 1st JUnit 5 test! 😎"
,
testInfo
.
getDisplayName
(),
()
->
"TestInfo is injected correctly"
);
}
}
src/test/java/token/OneTimeTokenTests.java
View file @
79553c0b
package
token
;
package
token
;
import
cn.quantgroup.xyqb.Bootstrap
;
import
cn.quantgroup.xyqb.Bootstrap
;
import
cn.quantgroup.xyqb.Constants
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
...
@@ -12,7 +11,7 @@ import org.junit.runner.RunWith;
...
@@ -12,7 +11,7 @@ import org.junit.runner.RunWith;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.context.junit4.Spring
JUnit4Class
Runner
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.MvcResult
;
import
org.springframework.test.web.servlet.MvcResult
;
...
@@ -20,12 +19,9 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
...
@@ -20,12 +19,9 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.WebApplicationContext
;
import
java.nio.charset.Charset
;
import
java.util.Base64
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
@RunWith
(
Spring
JUnit4Class
Runner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@WebAppConfiguration
@WebAppConfiguration
public
class
OneTimeTokenTests
{
public
class
OneTimeTokenTests
{
...
...
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