尝试为 WPF 用户控件创建 NUnit 测试
Trying to create an NUnit test for WPF User Control
我已将我的 WPF 项目引用到我创建的 NUnit 测试项目。我正在尝试调用它的一个函数,但出现以下 compilation 错误:
Reference to type 'DependencyObject' claims it is defined in 'WindowsBase', but it could not be found
我在 NUnit 测试的 "Assemblies" 部分添加了 PresentationFramework、PresentationCore 和 WindowsBase 作为参考,但没有成功...不确定我做错了什么...代码非常基础。 ..
using NUnit.Framework;
using System.Collections.Generic;
using System.Threading;
using CM;
namespace Tests
{
[TestFixture, Apartment(ApartmentState.STA)]
public class Tests
{
InstUserControl userControlMV = new InstUserControl ();
[Test]
public void Test1()
{
List<string> pOptions = new List<string>() { "2x4", "4x6" };
userControlMV.SetPOptions(pOptions);
Assert.Pass();
}
}
}
谁知道我做错了什么。
您不能创建 NUnit Test Project (.NET Core)
来测试面向 .NET Framework 的 WPF 应用程序。这是你应该做的:
- 新建一个
Unit Test Project (.NET Framwork)
- 将
NUnit
和 NUnit3TestAdapter
NuGet 包安装到其中
- 添加对要测试的 WPF 项目的引用
- 添加对 PresentationFramework.dll
的引用
- 添加对 PresentationCore.cll
的引用
- 添加对 WindowsBase.dll
的引用
- 运行 你的测试。
我已将我的 WPF 项目引用到我创建的 NUnit 测试项目。我正在尝试调用它的一个函数,但出现以下 compilation 错误:
Reference to type 'DependencyObject' claims it is defined in 'WindowsBase', but it could not be found
我在 NUnit 测试的 "Assemblies" 部分添加了 PresentationFramework、PresentationCore 和 WindowsBase 作为参考,但没有成功...不确定我做错了什么...代码非常基础。 ..
using NUnit.Framework;
using System.Collections.Generic;
using System.Threading;
using CM;
namespace Tests
{
[TestFixture, Apartment(ApartmentState.STA)]
public class Tests
{
InstUserControl userControlMV = new InstUserControl ();
[Test]
public void Test1()
{
List<string> pOptions = new List<string>() { "2x4", "4x6" };
userControlMV.SetPOptions(pOptions);
Assert.Pass();
}
}
}
谁知道我做错了什么。
您不能创建 NUnit Test Project (.NET Core)
来测试面向 .NET Framework 的 WPF 应用程序。这是你应该做的:
- 新建一个
Unit Test Project (.NET Framwork)
- 将
NUnit
和NUnit3TestAdapter
NuGet 包安装到其中 - 添加对要测试的 WPF 项目的引用
- 添加对 PresentationFramework.dll 的引用
- 添加对 PresentationCore.cll 的引用
- 添加对 WindowsBase.dll 的引用
- 运行 你的测试。