C# 为什么我的NUnit测试没有从用户设置配置文件加载值?
命名空间“AndroidAuto”包含以下代码:C# 为什么我的NUnit测试没有从用户设置配置文件加载值?,c#,nunit,settings,C#,Nunit,Settings,命名空间“AndroidAuto”包含以下代码: static void Main(string[] args) { AndroidAuto.Properties.Settings.Default.DeviceName = "droid"; AndroidAuto.Properties.Settings.Default.DeviceType = "Android"; AndroidAuto.Properties.Se
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();
}
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();
}
命名空间“AndroidAuto.WordPressTests”包含代码:
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();
}
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文件包含:
app.config在测试项目中。您提到的app.config是测试项目中的吗?是的,它在测试项目中。也许您必须将值设置为设置
某些值
,我看到您在Main
方法中设置了值,并且在测试它时没有执行此方法。