2

我正在使用Win7 x64. 我的某些部分测试需要使用仅表示支持 x86 的 SQLServer CE。我正在使用Visual Studio 2010 Express,我必须为我的项目更改平台目标,手动编辑 *.cproj 文件以运行,例如schema export test (NHibernate). 为什么我会根据平台目标运行部分测试。

谢谢!

4

1 回答 1

2

我不知道 NUnit 中是否有内置机制来处理这种情况,但至少你可以使用预处理器指令。

例如,创建一个针对 x86 的“Debug x86”解决方案配置。然后定义 DEBUG_X86 条件编译符号(在项目的属性中)。最后,用预处理器指令包围你的单元测试:

#if DEBUG_X86
[Test]
public void Test()
{
    // This test will only run when compiled with Debug x86
}
#endif

编辑:实际上,您甚至不必创建新的解决方案配置,因为可以根据平台定义条件符号(https://stackoverflow.com/a/1313450/869621)。所以定义一个 WIN32 编译符号,并用它包围你的测试:

#if WIN32
[Test]
public void Test()
{
    // This test will only run when compiled for x86
}
#endif
于 2011-12-28T08:11:44.940 回答