为什么我的NUnit测试没有加载用户设置配置文件中的值?

时间:2015-11-07 23:52:33

标签: c# nunit settings

命名空间'AndroidAuto'包含代码:

        static void Main(string[] args)
        {
        AndroidAuto.Properties.Settings.Default.DeviceName = "droid";
        AndroidAuto.Properties.Settings.Default.DeviceType = "Android";
        AndroidAuto.Properties.Settings.Default.DeviceVersion = "5.0.1-234";
        AndroidAuto.Properties.Settings.Default.AppLocationPath = @"C:\WordPress.apk";
        AndroidAuto.Properties.Settings.Default.AppPackage = "org.wordpress.android";
        AndroidAuto.Properties.Settings.Default.Save();
        AndroidAuto.Properties.Settings.Default.Reload();

        string[] my_args = { "/fixture=" + typeof(Tests), Assembly.GetExecutingAssembly().Location };

        int returnCode = NUnit.ConsoleRunner.Runner.Main(my_args);

        if (returnCode != 0)
            Console.Beep();

        Console.ReadLine();
        }

命名空间'AndroidAuto.WordPressTests'包​​含代码:

        static MyDevice GetDeviceInfo()
        {
        MyDevice device = new MyDevice();
        device.Name = AndroidAuto.Properties.Settings.Default.DeviceName;
        device.Type = (PlatformType)Enum.Parse(typeof(PlatformType), Properties.Settings.Default.DeviceType);
        device.Version = Properties.Settings.Default.DeviceVersion;
        device.NoReset = Convert.ToBoolean(ConfigurationManager.AppSettings["NoReset"]);
        device.CommandTimeout = Convert.ToInt32(ConfigurationManager.AppSettings["CommandTimeout"]);
        device.AppLocationPath = Properties.Settings.Default.AppLocationPath;
        device.AppPackage = Properties.Settings.Default.AppPackage;

        return device;
        }

    [TestFixtureSetUp]
    public void Setup()
    {
        MyDevice device = GetDeviceInfo();
    }

但是,没有读取任何用户设置。他们返回“”。我错过了什么?

App.config文件包含:

<userSettings> <AndroidAuto.Properties.Settings> <setting name="DeviceName" serializeAs="String"> <value /> </setting> <setting name="DeviceType" serializeAs="String"> <value /> </setting> <setting name="DeviceVersion" serializeAs="String"> <value /> </setting> <setting name="AppLocationPath" serializeAs="String"> <value /> </setting> <setting name="AppPackage" serializeAs="String"> <value /> </setting> </AndroidAuto.Properties.Settings> </userSettings>

app.config位于测试项目中。

0 个答案:

没有答案