Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
DEMO
spring-boot
Commits
5c44c772
Commit
5c44c772
authored
Jul 06, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document auto-configuration classes imported by each @…Test annotation
Closes gh-6044
parent
5bfc6a50
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
153 additions
and
0 deletions
+153
-0
pom.xml
spring-boot-docs/pom.xml
+25
-0
appendix-test-auto-configuration.adoc
...s/src/main/asciidoc/appendix-test-auto-configuration.adoc
+7
-0
appendix.adoc
spring-boot-docs/src/main/asciidoc/appendix.adoc
+1
-0
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+11
-0
generateTestSlicesTable.groovy
...-boot-docs/src/main/groovy/generateTestSlicesTable.groovy
+109
-0
No files found.
spring-boot-docs/pom.xml
View file @
5c44c772
...
@@ -886,6 +886,25 @@
...
@@ -886,6 +886,25 @@
</artifactItems>
</artifactItems>
</configuration>
</configuration>
</execution>
</execution>
<execution>
<id>
unpack-test-slices
</id>
<phase>
generate-resources
</phase>
<goals>
<goal>
unpack
</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-test-autoconfigure
</artifactId>
<version>
${project.version}
</version>
<outputDirectory>
${project.build.directory}/test-auto-config
</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</executions>
</plugin>
</plugin>
<plugin>
<plugin>
...
@@ -932,6 +951,7 @@
...
@@ -932,6 +951,7 @@
<scripts>
<scripts>
<script>
file:///${project.basedir}/src/main/groovy/generateAutoConfigurationClassTables.groovy
</script>
<script>
file:///${project.basedir}/src/main/groovy/generateAutoConfigurationClassTables.groovy
</script>
<script>
file:///${project.basedir}/src/main/groovy/generateStarterTables.groovy
</script>
<script>
file:///${project.basedir}/src/main/groovy/generateStarterTables.groovy
</script>
<script>
file:///${project.basedir}/src/main/groovy/generateTestSlicesTable.groovy
</script>
</scripts>
</scripts>
</configuration>
</configuration>
<dependencies>
<dependencies>
...
@@ -940,6 +960,11 @@
...
@@ -940,6 +960,11 @@
<artifactId>
groovy-all
</artifactId>
<artifactId>
groovy-all
</artifactId>
<version>
${groovy.version}
</version>
<version>
${groovy.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-core
</artifactId>
<version>
${spring.version}
</version>
</dependency>
</dependencies>
</dependencies>
</plugin>
</plugin>
<plugin>
<plugin>
...
...
spring-boot-docs/src/main/asciidoc/appendix-test-auto-configuration.adoc
0 → 100644
View file @
5c44c772
[appendix]
[[test-auto-configuration]]
== Test auto-configuration annotations
Here is a table of the various `@…Test` annotations that can be used to test
slices of your application and the auto-configuration that they import by default:
include::../../../target/generated-resources/test-slice-auto-configuration.adoc[]
\ No newline at end of file
spring-boot-docs/src/main/asciidoc/appendix.adoc
View file @
5c44c772
...
@@ -4,5 +4,6 @@
...
@@ -4,5 +4,6 @@
include::appendix-application-properties.adoc[]
include::appendix-application-properties.adoc[]
include::appendix-configuration-metadata.adoc[]
include::appendix-configuration-metadata.adoc[]
include::appendix-auto-configuration-classes.adoc[]
include::appendix-auto-configuration-classes.adoc[]
include::appendix-test-auto-configuration.adoc[]
include::appendix-executable-jar-format.adoc[]
include::appendix-executable-jar-format.adoc[]
include::appendix-dependency-versions.adoc[]
include::appendix-dependency-versions.adoc[]
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
5c44c772
...
@@ -4879,6 +4879,9 @@ NOTE: JSON helper classes can also be used directly in standard unit tests. Simp
...
@@ -4879,6 +4879,9 @@ NOTE: JSON helper classes can also be used directly in standard unit tests. Simp
call the `initFields` method of the helper in your `@Before` method if you aren't using
call the `initFields` method of the helper in your `@Before` method if you aren't using
`@JsonTest`.
`@JsonTest`.
A list of the auto-configuration that is enabled by `@JsonTest` can be
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-mvc-tests]]
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-mvc-tests]]
...
@@ -4971,6 +4974,9 @@ and/or a `WebDriver` bean. Here is an example that uses HtmlUnit:
...
@@ -4971,6 +4974,9 @@ and/or a `WebDriver` bean. Here is an example that uses HtmlUnit:
}
}
----
----
A list of the auto-configuration that is enabled by `@WebMvcTest` can be
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-jpa-test]]
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-jpa-test]]
...
@@ -5053,6 +5059,8 @@ database you can use the `@AutoConfigureTestDatabase` annotation:
...
@@ -5053,6 +5059,8 @@ database you can use the `@AutoConfigureTestDatabase` annotation:
}
}
----
----
A list of the auto-configuration that is enabled by `@DataJpaTest` can be
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
...
@@ -5088,6 +5096,9 @@ be specified using `value` or `components` attribute of `@RestClientTest`:
...
@@ -5088,6 +5096,9 @@ be specified using `value` or `components` attribute of `@RestClientTest`:
}
}
----
----
A list of the auto-configuration that is enabled by `@RestClientTest` can be
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-rest-docs]]
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-rest-docs]]
...
...
spring-boot-docs/src/main/groovy/generateTestSlicesTable.groovy
0 → 100644
View file @
5c44c772
import
groovy.io.FileType
import
java.util.Properties
import
org.springframework.core.io.InputStreamResource
import
org.springframework.core.io.Resource
import
org.springframework.core.type.AnnotationMetadata
import
org.springframework.core.type.ClassMetadata
import
org.springframework.core.type.classreading.MetadataReader
import
org.springframework.core.type.classreading.MetadataReaderFactory
import
org.springframework.core.type.classreading.SimpleMetadataReaderFactory
import
org.springframework.util.ClassUtils
import
org.springframework.util.StringUtils
class
Project
{
final
List
<
File
>
classFiles
final
Properties
springFactories
Project
(
File
rootDirectory
)
{
this
.
springFactories
=
loadSpringFactories
(
rootDirectory
)
this
.
classFiles
=
[]
rootDirectory
.
eachFileRecurse
(
FileType
.
FILES
)
{
file
->
if
(
file
.
name
.
endsWith
(
'.class'
))
{
classFiles
<<
file
}
}
}
private
static
Properties
loadSpringFactories
(
File
rootDirectory
)
{
Properties
springFactories
=
new
Properties
()
new
File
(
rootDirectory
,
'META-INF/spring.factories'
).
withInputStream
{
inputStream
->
springFactories
.
load
(
inputStream
)
}
return
springFactories
}
}
class
TestSlice
{
final
String
name
final
SortedSet
<
String
>
importedAutoConfiguration
TestSlice
(
String
annotationName
,
Collection
<
String
>
importedAutoConfiguration
)
{
this
.
name
=
ClassUtils
.
getShortName
(
annotationName
)
this
.
importedAutoConfiguration
=
new
TreeSet
<
String
>(
importedAutoConfiguration
)
}
}
List
<
TestSlice
>
createTestSlices
(
Project
project
)
{
MetadataReaderFactory
metadataReaderFactory
=
new
SimpleMetadataReaderFactory
()
project
.
classFiles
.
findAll
{
classFile
->
classFile
.
name
.
endsWith
(
'Test.class'
)
}.
collect
{
classFile
->
createMetadataReader
(
metadataReaderFactory
,
classFile
)
}.
findAll
{
metadataReader
->
metadataReader
.
classMetadata
.
annotation
}.
collect
{
metadataReader
->
createTestSlice
(
project
.
springFactories
,
metadataReader
.
classMetadata
,
metadataReader
.
annotationMetadata
)
}.
sort
{
a
,
b
->
a
.
name
.
compareTo
b
.
name
}
}
MetadataReader
createMetadataReader
(
MetadataReaderFactory
factory
,
File
classFile
)
{
classFile
.
withInputStream
{
inputStream
->
factory
.
getMetadataReader
(
new
InputStreamResource
(
inputStream
))
}
}
TestSlice
createTestSlice
(
Properties
springFactories
,
ClassMetadata
classMetadata
,
AnnotationMetadata
annotationMetadata
)
{
new
TestSlice
(
classMetadata
.
className
,
getImportedAutoConfiguration
(
springFactories
,
classMetadata
,
annotationMetadata
))
}
Set
<
String
>
getImportedAutoConfiguration
(
Properties
springFactories
,
ClassMetadata
classMetadata
,
AnnotationMetadata
annotationMetadata
)
{
annotationMetadata
.
annotationTypes
.
findAll
{
annotationType
->
isAutoConfigurationImporter
(
annotationType
,
annotationMetadata
)
}.
collect
{
autoConfigurationImporter
->
StringUtils
.
commaDelimitedListToSet
(
springFactories
.
get
(
autoConfigurationImporter
))
}.
flatten
()
}
boolean
isAutoConfigurationImporter
(
String
annotationType
,
AnnotationMetadata
metadata
)
{
metadata
.
getMetaAnnotationTypes
(
annotationType
).
contains
(
'org.springframework.boot.autoconfigure.ImportAutoConfiguration'
)
}
void
writeTestSlicesTable
(
List
<
TestSlice
>
testSlices
)
{
new
File
(
project
.
build
.
directory
,
"generated-resources/test-slice-auto-configuration.adoc"
).
withPrintWriter
{
writer
->
writer
.
println
'[cols="d,a"]'
writer
.
println
'|==='
writer
.
println
'| Test slice | Imported auto-configuration'
testSlices
.
each
{
testSlice
->
writer
.
println
''
writer
.
println
"| `@${testSlice.name}`"
writer
.
print
'| '
testSlice
.
importedAutoConfiguration
.
each
{
writer
.
println
"`${it}`"
}
}
writer
.
println
'|==='
}
}
List
<
TestSlice
>
testSlices
=
createTestSlices
(
new
Project
(
new
File
(
project
.
build
.
directory
,
'test-auto-config'
)))
writeTestSlicesTable
(
testSlices
)
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