2

I am very new to Specflow/Specrun and C# programming. I need help in fixing the issue I am facing.

I have a Specrun feature file which queries database. Below is the code of the feature file:

Scenario Outline: Ensure all rows are correctly inserted on in the table
    Given I am connected to "Database-XYZ"
    When I run a script to ensure all rows are inserted for <tableName> of a <schemaName>
    Then All tables have correct <columnCount> count.

This works absolutely fine. But I want to comment the second line and specify the database name at run time using the default.srprofile file.

I want to execute runtests.cmd file (from commandline) using default.srprofile file and feed the database name at run time. Is it possible to achieve this?

4

1 に答える 1

2

これが役立つかどうかはわかりませんが、app.config を使用することをお勧めします。データベースと環境を設定し、ステップから呼び出します。このようにして、app.config の値を変更するだけで、呼び出しを作成し、テスト中の環境に従ってデータベースを設定できます。以下のようなことができます。

 app.config
 <add key="DatabaseTest" value="myDBConnectionString" />
 <add key="DatabaseDev" value="myDBConnectionString" />
 <add key="Environment" value="test" />

 Step:
 using System.Configuration; //make sure you have this included to use ConfigurationManager

    [Given(@"I am connected to my environment database")]
    public void GivenIAmConnectedToMyEnvironmentDatabase()
    {

     var myEnv = ConfigurationManager.AppSettings["Environment"];
     switch (myEnv)
     {
       case "test":
         var  _testDatabase = ConfigurationManager.AppSettings["DatabaseTest"];
         //create db connection 
         break;
       case "dev":
          var _devDatabase = ConfigurationManager.AppSettings["DatabaseDev"];
          //create db connection 
          break;
     }
     }
于 2016-11-12T03:59:09.543 に答える