Automation 在运行时切换App.Config设置#

Automation 在运行时切换App.Config设置#,automation,nunit,app-config,leanft,Automation,Nunit,App Config,Leanft,我想知道切换C#的App.Config设置的最佳方法是什么。这涉及到我们的测试套件,我们希望选择远程或本地环境来启动测试。我们使用LeanFT和NUnit作为我们的测试框架,目前为了让测试远程运行,我们必须在App.config文件中添加一个配置。当我通过命令行启动这些测试时,如何在运行时指定不同的配置?谢谢 任何leanft配置都可以在运行时通过使用SDK命名空间或Report命名空间进行修改 下面是一个使用NUnit 3的示例,展示了如何实现这一点 using NUnit.Framework

我想知道切换C#的App.Config设置的最佳方法是什么。这涉及到我们的测试套件,我们希望选择远程或本地环境来启动测试。我们使用LeanFT和NUnit作为我们的测试框架,目前为了让测试远程运行,我们必须在App.config文件中添加一个
配置。当我通过命令行启动这些测试时,如何在运行时指定不同的配置?谢谢

任何leanft配置都可以在运行时通过使用
SDK
命名空间或
Report
命名空间进行修改

下面是一个使用NUnit 3的示例,展示了如何实现这一点

using NUnit.Framework;
using HP.LFT.SDK;
using HP.LFT.Report;
using System;

namespace LeanFtTestProject
{
    [TestFixture]
    public class LeanFtTest
    {
        [OneTimeSetUp]
        public void TestFixtureSetUp()
        {
            // Initialize the SDK
            SDK.Init(new SdkConfiguration()
            {
                AutoLaunch = true,
                ConnectTimeoutSeconds = 20,
                Mode = SDKMode.Replay,
                ResponseTimeoutSeconds = 20,
                ServerAddress = new Uri("ws://127.0.0.1:5095") // local or remote, decide at runtime
            });

            // Initialize the Reporter (if you want to use it, ofc)
            Reporter.Init(new ReportConfiguration()
            {
                Title = "The Report title",
                Description = "The report description",
                ReportFolder = "RunResults",
                IsOverrideExisting = true,
                TargetDirectory = "", // which means the current parent directory 
                ReportLevel = ReportLevel.All,
                SnapshotsLevel = CaptureLevel.All
            });

        }

        [SetUp]
        public void SetUp()
        {
            // Before each test
        }

        [Test]
        public void Test()
        {
            Reporter.ReportEvent("Doing something", "Description");
        }

        [TearDown]
        public void TearDown()
        {
            // Clean up after each test
        }

        [OneTimeTearDown]
        public void TestFixtureTearDown()
        {
            // If you used the reporter, invoke this at the end of the tests
            Reporter.GenerateReport();

            // And perform this cleanup as the last leanft step
            SDK.Cleanup();
        }
    }
}

这似乎是硬编码,但在我将无法切换它。我有一个运行本地的默认App.Config设置。我想定义一个额外的配置,我可以通过一些命令行参数进行切换。我可以用这种方法吗?当然可以。这甚至不是
LeanFT
,这是
C#
——您定义了一个名为
serverToUse
的变量,并在
SdkConfiguration
构造函数(AKA
newuri(serverToUse)
ServerAddress
属性中使用它。要解析命令行参数,您可以从