Scala:使用 Play 框架进行模板测试
Scala : Template testing with Play framework
我正在从 Java 过渡到 Scala。我正在寻找一种方法来进行类似于 :
的测试
//As a template is a just a method, you can execute it from a test and check the result:
@Test
public void renderTemplate() {
Content html = views.html.index.render("Welcome to Play!");
assertEquals("text/html", html.contentType());
assertTrue(contentAsString(html).contains("Welcome to Play!"));
}
我在这里找到它:https://www.playframework.com/documentation/2.8.x/JavaTest
任何在文档中找到它以在 scala 中编写类似测试的尝试都失败了。有人可以帮忙吗?
这类测试在 PlayFramework 中称为 Functional Tests
是的,有用于编写功能测试和测试模板的详细文档示例。以下代码示例是 Scala
中的替代版本
"render index template" in {
val html = views.html.index("Hello")
contentType(html) must equalTo("text/html")
contentAsString(html) must contain("Welcome to Play!")
}
例子2。测试路由器:
"respond to the index Action" in {
val Some(result) = routeAndCall(FakeRequest(GET, "/Bob"))
status(result) must equalTo(OK)
contentType(result) must beSome("text/html")
charset(result) must beSome("utf-8")
contentAsString(result) must contain("Hello Bob")
}
我正在从 Java 过渡到 Scala。我正在寻找一种方法来进行类似于 :
的测试//As a template is a just a method, you can execute it from a test and check the result:
@Test
public void renderTemplate() {
Content html = views.html.index.render("Welcome to Play!");
assertEquals("text/html", html.contentType());
assertTrue(contentAsString(html).contains("Welcome to Play!"));
}
我在这里找到它:https://www.playframework.com/documentation/2.8.x/JavaTest 任何在文档中找到它以在 scala 中编写类似测试的尝试都失败了。有人可以帮忙吗?
这类测试在 PlayFramework 中称为 Functional Tests 是的,有用于编写功能测试和测试模板的详细文档示例。以下代码示例是 Scala
中的替代版本"render index template" in {
val html = views.html.index("Hello")
contentType(html) must equalTo("text/html")
contentAsString(html) must contain("Welcome to Play!")
}
例子2。测试路由器:
"respond to the index Action" in {
val Some(result) = routeAndCall(FakeRequest(GET, "/Bob"))
status(result) must equalTo(OK)
contentType(result) must beSome("text/html")
charset(result) must beSome("utf-8")
contentAsString(result) must contain("Hello Bob")
}