Note that there are some explanatory texts on larger screens.

plurals
  1. POTests with different data models
    text
    copied!<p>Many of my class level unit tests load a data model and perform various class level tests. However, much of the business logic depends on the data in the model. Therefore my class level testing looks like this:</p> <pre><code> public class TestFoo { // Data model Model _myDataModel; // Class under test Foo _foo; [Setup] public void Initialize() { // Create data model _myDataModel = new Model(); _myDataModel.Load(); // Loads the file // Create the class under test _foo = new Foo(); } [TearDown] public void Dispose() { } [Test] public void TestFooCase1() { // Code for test case that tests _foo and uses the data model } } </code></pre> <p>However, I would like to run the bulk of my tests with two or more data models, i.e. I need to call<code>_myDataModel.LoadModelX()</code> or <code>_myDataModel.LoadModelY()</code> in the setup method.</p> <p>One way I thought of doing this is by instantiating the model in the test case itself as shown below but this requires having to call the load method in every test case. </p> <pre><code>[Setup] public void Initialize() { // Create the class under test _foo = new Foo(); } [TearDown] public void Dispose() { } // Use TestCase to specify the model as an argument for each test case [TestCase(modelX)] [TestCase(modelY)] public void TestFooCase1(string modelName) { // Create data model _myDataModel = new Model(); _myDataModel.Load(modelName); // New method which loads the specific model // Code for test case that tests _foo and uses the data model } </code></pre> <p>I'm thinking there must be a better approach possibly by defining my own attribute or extending the NUnitTestFixture. I'm interested in other ideas.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload