开发者

How to use test-data w/o deleting 'old' information?

As described in the playframework documentation, I'd like to import data from the yaml-file in order to perfor开发者_Python百科m tests. However, I'd like to keep - or at least roll back after the tests - the existing entries in the database.

Any hints are appreciated.

regards

- alex


The easiest approach is to use the Fixtures.

So, in your unit/functional test, you can do

@Before
public void setup() {
   Fixtures.deleteAll();
   Fixtures.load("data.yml");
}

This will clear all the data out, and reload the data into the database before the test is executed.

To achieve the same thing for your selenium tests, you just do

#{selenium delete:'all', load:'data.yml'}

You can't easily revert the database back to what is was prior to the unit test, but I would suggest that your test database should be entirely populated by your YAML file anyway, so that you have complete control over the data that your tests are be tested over.


As far as I can estimate, dbUnit, an extension of JUnit, would be an appropriate solution for this problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜