我正在从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中编写类似的测试。有人能帮上忙吗?
发布于 2020-04-10 21:21:20
这种类型的测试在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!")
}Example2。测试路由器:
"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")
}https://stackoverflow.com/questions/61131727
复制相似问题