When do I use the TestFixtureSetUp attribute instead of a default constructor?

前端 未结 9 1120
旧巷少年郎
旧巷少年郎 2021-01-30 15:59

The NUnit documentation doesn\'t tell me when to use a method with a TestFixtureSetup and when to do the setup in the constructor.

public class MyTe         


        
9条回答
  •  故里飘歌
    2021-01-30 16:28

    One thing you can't do with [TestFixtureSetup] that you can do in the constructor is receive parameters from the [TestFixture] .

    If you want to parameterise your test fixture, then you will have to use the constructor for at least some of the set-up. So far, I've only used this for integration tests, e.g. for testing a data access layer with multiple data providers:

    [TestFixture("System.Data.SqlClient",
      "Server=(local)\\SQLEXPRESS;Initial Catalog=MyTestDatabase;Integrated Security=True;Pooling=False"))]
    [TestFixture("System.Data.SQLite", "Data Source=MyTestDatabase.s3db")])]
    internal class MyDataAccessLayerIntegrationTests
    {
        MyDataAccessLayerIntegrationTests(
            string dataProvider,
            string connectionString)
        {
            ...
        }
    }
    

提交回复
热议问题