简体   繁体   中英

playframework testing - set up and tear down - how to?

I've started using playframwork (scala) and I'm writing some tests. Before starting them I'd like to put in some mock data in my db (mongo) and later on when the tests are over remove this data. I've got the code to put/remove this data but can't figure out how to consistently get this done before/after the tests are run.

I'm using the "specs2" testing library that comes with playframework but was unable to find any docs on how this can be done with specs.

Do you know how this can be done with specs? or can recommend another well known testing lib for playframework that I should use instead of specs?

我没有对其进行测试,但是从文档来看,Specs2似乎支持“之前/之后”方法: http ://etorreborre.github.io/specs2/guide/org.specs2.guide.Structure.html#Before%2FAfter

You can find some running examples here on GitHub . It's from a pet project of mine, written in Scala with the Play Framork version 2.1.0.

The keypart is the following:

"Application" should {
  "work from within a browser" in {
    running(TestServer(3333), HTMLUNIT) { browser =>

This starts up the Play application on port 3333. Before this you can add the code for your test fixtures etc.

If you want the sytem to assign a free port for the tests, you can have a look here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM