我想在play framework 2.1.*
路线代码:
# Home page
GET / controllers.Application.index()
POST /signup controllers.Application.signup()
和控制器是:
public class Application extends Controller {
final static Form<User> usr=form(User.class);
public static Result index() {
return ok(index.render(usr));
}
和查看部分是:
index.scala.html
@(signupform: Form[User])
@import helper._
@import helper.twitterBootstrap._
@main("welcome to EXTR ") {
<div class="container-narrow">
<fieldset>
<legend>Sign up or <a href="@routes.signin.page" >Sign in</a></legend>
@helper.form(action=routes.Application.signup()){
@inputText(
signupform("username"),
'_label->"Enter Username",
'_help -> "Please Enter a valid username.",
'_error -> signupform.globalError)
@inputText(
signupform("name"),
'_label->"Enter name",
'_error -> signupform.globalError)
@inputPassword(
signupform("password"),
'_label->"Enter Password",
'_help -> "Please Enter a valid Password.",
'_error -> signupform.globalError)
@inputPassword(
signupform("repassword"),
'_label->"Enter Password again",
'_error -> signupform.globalError)
@inputText(
signupform("email"),
'_label->"Enter email",
'_help -> "Please Enter a valid Email",
'_error -> signupform.globalError)
<input class="btn btn-large " type="submit" value="signup" />
}
</fieldset></div>
}
现在我想测试index.scala.html
如何为此编写测试代码?
我尝试了但没有得到
@Test
public void renderTemplate() {
Content html = views.html.index.render(form(User.class));
assertThat(contentType(html)).isEqualTo("text/html");
assertThat(contentAsString(html)).contains("Coco");
}
但是当我没有得到任何回复时,它会继续运行吗?
那么请给我一些想法为此编写代码?
答案 0 :(得分:1)
我认为你正在寻找一些验收测试,
所以这是我的scala-play项目的一个例子。 你可以从中得到一个想法。
"A Track view" should "render basic data" in running(TestServer(3333)) {
await(WS.url("http://localhost:3333/track/62584001").get).status must equal (OK)
await(WS.url("http://localhost:3333/track/62584001").get).body must include ("62584001")
}