Browse Source

Fix errors in Testing chapter

- group code example callouts to ensure callouts are displayed for the
  correct examples

- add missing callouts

- fix syntax, annotation attribute names, etc.
pull/29602/head
Sam Brannen 2 years ago
parent
commit
2847621928
  1. 13
      framework-docs/src/docs/asciidoc/testing/spring-mvc-test-framework.adoc
  2. 7
      framework-docs/src/docs/asciidoc/testing/testcontext-framework.adoc
  3. 7
      framework-docs/src/docs/asciidoc/testing/testing-annotations.adoc

13
framework-docs/src/docs/asciidoc/testing/spring-mvc-test-framework.adoc

@ -1429,6 +1429,7 @@ Now we can use WebDriver as we normally would but without the need to deploy our @@ -1429,6 +1429,7 @@ Now we can use WebDriver as we normally would but without the need to deploy our
application to a Servlet container. For example, we can request the view to create a
message with the following:
--
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
@ -1440,9 +1441,11 @@ message with the following: @@ -1440,9 +1441,11 @@ message with the following:
----
val page = CreateMessagePage.to(driver)
----
--
We can then fill out the form and submit it to create a message, as follows:
--
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
@ -1456,6 +1459,7 @@ We can then fill out the form and submit it to create a message, as follows: @@ -1456,6 +1459,7 @@ We can then fill out the form and submit it to create a message, as follows:
val viewMessagePage =
page.createMessage(ViewMessagePage::class, expectedSummary, expectedText)
----
--
This improves on the design of our <<spring-mvc-test-server-htmlunit-mah-usage, HtmlUnit test>>
by leveraging the Page Object Pattern. As we mentioned in
@ -1463,6 +1467,7 @@ by leveraging the Page Object Pattern. As we mentioned in @@ -1463,6 +1467,7 @@ by leveraging the Page Object Pattern. As we mentioned in
with HtmlUnit, but it is much easier with WebDriver. Consider the following
`CreateMessagePage` implementation:
--
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
@ -1551,11 +1556,12 @@ by the `id` or `name` of the element within the HTML page. @@ -1551,11 +1556,12 @@ by the `id` or `name` of the element within the HTML page.
https://github.com/SeleniumHQ/selenium/wiki/PageFactory#making-the-example-work-using-annotations[`@FindBy` annotation]
to override the default lookup behavior. Our example shows how to use the `@FindBy`
annotation to look up our submit button with a `css` selector (*input[type=submit]*).
--
Finally, we can verify that a new message was created successfully. The following
assertions use the https://assertj.github.io/doc/[AssertJ] assertion library:
--
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
@ -1568,10 +1574,12 @@ assertions use the https://assertj.github.io/doc/[AssertJ] assertion library: @@ -1568,10 +1574,12 @@ assertions use the https://assertj.github.io/doc/[AssertJ] assertion library:
assertThat(viewMessagePage.message).isEqualTo(expectedMessage)
assertThat(viewMessagePage.success).isEqualTo("Successfully created a new message")
----
--
We can see that our `ViewMessagePage` lets us interact with our custom domain model. For
example, it exposes a method that returns a `Message` object:
--
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
@ -1589,12 +1597,14 @@ example, it exposes a method that returns a `Message` object: @@ -1589,12 +1597,14 @@ example, it exposes a method that returns a `Message` object:
----
fun getMessage() = Message(getId(), getCreated(), getSummary(), getText())
----
--
We can then use the rich domain objects in our assertions.
Lastly, we must not forget to close the `WebDriver` instance when the test is complete,
as follows:
--
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
@ -1616,6 +1626,7 @@ as follows: @@ -1616,6 +1626,7 @@ as follows:
}
}
----
--
For additional information on using WebDriver, see the Selenium
https://github.com/SeleniumHQ/selenium/wiki/Getting-Started[WebDriver documentation].

7
framework-docs/src/docs/asciidoc/testing/testcontext-framework.adoc

@ -644,7 +644,7 @@ path that represents a resource URL (i.e., a path prefixed with `classpath:`, `f @@ -644,7 +644,7 @@ path that represents a resource URL (i.e., a path prefixed with `classpath:`, `f
@ExtendWith(SpringExtension::class)
// ApplicationContext will be loaded from "/app-config.xml" and
// "/test-config.xml" in the root of the classpath
@ContextConfiguration("/app-config.xml", "/test-config.xml") // <1>
@ContextConfiguration(locations = ["/app-config.xml", "/test-config.xml"]) // <1>
class MyTest {
// class body...
}
@ -667,7 +667,7 @@ demonstrated in the following example: @@ -667,7 +667,7 @@ demonstrated in the following example:
// class body...
}
----
<1> Specifying XML files without using the `location` attribute.
<1> Specifying XML files without using the `locations` attribute.
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
@ -678,7 +678,7 @@ demonstrated in the following example: @@ -678,7 +678,7 @@ demonstrated in the following example:
// class body...
}
----
<1> Specifying XML files without using the `location` attribute.
<1> Specifying XML files without using the `locations` attribute.
If you omit both the `locations` and the `value` attributes from the
@ -743,6 +743,7 @@ The following example shows how to specify Groovy configuration files: @@ -743,6 +743,7 @@ The following example shows how to specify Groovy configuration files:
// class body...
}
----
<1> Specifying the location of Groovy configuration files.
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin

7
framework-docs/src/docs/asciidoc/testing/testing-annotations.adoc

@ -222,6 +222,7 @@ resource base path). The resource base path is used behind the scenes to create @@ -222,6 +222,7 @@ resource base path). The resource base path is used behind the scenes to create
The following example shows how to use the `@WebAppConfiguration` annotation:
--
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
@ -231,6 +232,7 @@ The following example shows how to use the `@WebAppConfiguration` annotation: @@ -231,6 +232,7 @@ The following example shows how to use the `@WebAppConfiguration` annotation:
// class body...
}
----
<1> The `@WebAppConfiguration` annotation.
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
@ -242,6 +244,7 @@ The following example shows how to use the `@WebAppConfiguration` annotation: @@ -242,6 +244,7 @@ The following example shows how to use the `@WebAppConfiguration` annotation:
}
----
<1> The `@WebAppConfiguration` annotation.
--
To override the default, you can specify a different base resource path by using the
@ -249,6 +252,7 @@ implicit `value` attribute. Both `classpath:` and `file:` resource prefixes are @@ -249,6 +252,7 @@ implicit `value` attribute. Both `classpath:` and `file:` resource prefixes are
supported. If no resource prefix is supplied, the path is assumed to be a file system
resource. The following example shows how to specify a classpath resource:
--
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
@ -270,6 +274,7 @@ resource. The following example shows how to specify a classpath resource: @@ -270,6 +274,7 @@ resource. The following example shows how to specify a classpath resource:
}
----
<1> Specifying a classpath resource.
--
Note that `@WebAppConfiguration` must be used in conjunction with
@ -1104,7 +1109,7 @@ annotation. The following example shows how to declare an SQL group: @@ -1104,7 +1109,7 @@ annotation. The following example shows how to declare an SQL group:
@SqlGroup({ // <1>
@Sql(scripts = "/test-schema.sql", config = @SqlConfig(commentPrefix = "`")),
@Sql("/test-user-data.sql")
)}
})
void userTest() {
// run code that uses the test schema and test data
}

Loading…
Cancel
Save