2

我想测试我的模板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");

    }

但是当我运行没有得到任何回复时,它会继续运行吗?

所以给我一些想法为此编写代码?

4

1 回答 1

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")
}
于 2013-08-29T10:11:52.057 回答