我正在尝试测试一些遗留数据库代码。我在很多情况下想要将
- 数据库设置为空状态
对于一组测试,请为每个组执行以下操作:
- 对于一组测试,将数据库设置为初始测试状态
- 运行这些测试
- 将数据库返回到空状态
在NUnit中,当使用 TestFixture 时,我能否保证整个夹具的测试以及 TestFixtureTearDown 在处理下一个 TestFixture 之前一起运行?我已经使用 Visual Studio 测试工具尝试过此操作,但情况似乎并非如此。
尝试这样做的主要原因是,有时在步骤 2 中使数据库进入状态的过程可能会很昂贵,而且我不想为每个测试用例都运行这个过程。
I am trying to test some legacy database code. I have many situations where I want to
- Set database in empty state
For a group of tests do the following for each group:
- for a group of tests, set the db to an inital test state
- run those tests
- return db back to empty state
In NUnit, when using a TestFixture am I guaranteed that the entire fixture's test will be run together as well as the TestFixtureTearDown before the next TestFixture gets processed? I've tried this using the Visual Studio test stuff and this doesn't appear to be the case.
The main reason for trying to do this, is that sometimes the process of getting the db to the state in step 2 can be expensive and I don't want to have to run this for each of the test cases.
发布评论
评论(1)
TestFixtureTearDown
将在使用TestFixture
进行的测试完成后执行。将此与 TestFixtureSetUp 结合起来应该可以在TestFixture
的基础上提供您正在寻找的行为。Visual Studio 中的单元测试框架不会与 NUnit 具有相同的语法。虽然所有基于 xUnit 的框架的测试方法都是相同的,但语法会有所不同。
TestFixtureTearDown
will be executed once the tests with theTestFixture
are completed. Coupling this withTestFixtureSetUp
should provide the beahivor your are seeking on aTestFixture
basis.The Unit Testing Framework in Visual Studio does not have the same syntax as NUnit. While the test approach is the same for all xUnit based frameworks the syntax will vary.