在运行时C#上切换app.config设置



我想知道要切换app.config设置的最佳方法是。这涉及我们的测试套件,我们希望选择选择远程环境或本地环境来启动测试。我们使用Leanft和Nunit作为我们的测试框架,目前为了获得运行远程测试,我们必须在app.config文件中添加<leanft></leanft>配置。当我通过命令行踢出这些测试时,如何在运行时间指定不同的配置?谢谢!

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

这是一个使用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();
        }
    }
}

相关内容

  • 没有找到相关文章

最新更新