在 MonoDevelop 2.4 中使用 NUnit 测试 Monotouch 应用程序
我对 Monotouch 和 Monodevelop 都很陌生。尝试开始使用 NUnit 时遇到了很多麻烦——我在网上找到的粗略参考资料似乎都与我在 UI 中看到的内容(Mac OS 10.6 上的 MonoDevelop 2.4)相匹配。我尝试过:
- 将“NUnit 程序集测试集合”项目添加到我的解决方案中。
- 将“空 MonoTouch 项目”项目添加到我的解决方案中,然后向其中添加 NUnit 程序集,并添加我的主项目作为参考。
- 将 C#“空项目”添加到我的解决方案中,并添加 NUnit、MonoTouch 和我自己的项目作为参考。这会产生一个构建错误,抱怨“‘[测试项目名称].exe’不包含适合入口点的静态‘Main’方法。”
(1) 产生了一种奇怪的项目,我只能向其中添加程序集——没有引用,当然也没有测试。
(2) 和 (3) 的行为几乎相同:
- 首先,构建错误抱怨没有静态“Main”方法。我可以通过在“构建”->“构建”中将编译目标更改为“库”来解决此问题。一般项目选项。
- 接下来,当我尝试运行测试(从“单元测试”选项卡)时,它说它正在使用“调试|iPhoneSimulator”配置运行它们。
- 测试结果面板显示此“正在运行测试”消息,而不显示任何其他输出。
- 计数保持在“测试:0 失败:0 忽略:0”。
显然我在这里做错了什么,但我应该做什么?
只是为了笑,这是我的测试。
using System;
using NUnit.Framework;
namespace mynamespace
{
[TestFixture]
public class NavItemTest
{
[Test]
public void TestAll()
{
Assert.AreEqual(4, NavItem.all().Count);
}
}
}
I'm new to both Monotouch and Monodevelop. Trying to get started with NUnit and I'm having a lot of trouble -- none of the sketchy references I can find on line seem to match what I'm seeing in the UI (MonoDevelop 2.4 on Mac OS 10.6). I've tried:
- Adding an "NUnit assembly test collection" project to my solution.
- Adding an "Empty MonoTouch Project" project to my solution, and then adding the NUnit assemblies to it, and adding my main project as a reference.
- Adding a C# "Empty Project" to my solution, and adding NUnit, MonoTouch, and my own project as references. This produces a build error complaining that "'[test project name].exe' does not contain a static 'Main' method suitable for an entry point."
(1) produces a strange sort of project to which I can only add assemblies -- no references and certainly no tests.
(2) and (3) behave pretty much identically:
- First, a build error complaining that there's no static 'Main' method. I can fix this by changing the compile target to "Library" in the Build -> General project options.
- Next, when I try to run the tests (from the Unit Testing tab), it says it's running them using the "Debug|iPhoneSimulator" configuration.
- The Test Results panel shows this "running tests" message, and never any other output.
- The counts stay at "Tests: 0 Failed: 0 Ignored: 0".
Clearly I'm doing something wrong here, but what am I supposed to be doing?
Just for grins, here's my test.
using System;
using NUnit.Framework;
namespace mynamespace
{
[TestFixture]
public class NavItemTest
{
[Test]
public void TestAll()
{
Assert.AreEqual(4, NavItem.all().Count);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您错过了,现在有一个可用于 MonoTouch 的 NUnitLite 运行程序,它设计用于与 UI 无关的代码并在设备(或模拟器)上执行。
请参阅:适用于 iOS 的 .NET 单元测试运行器
In case you missed it, there is now a NUnitLite runner available for MonoTouch which is designed to work for UI agnostic code and executed on devices (or simulator).
See: .NET Unit test runner for iOS
已经写下了一些迄今为止我们发现的最佳实践的细节。您可以在这里找到它: http://ben .phegan.name/index.php/2011/02/28/monotouch-and-unit-testing。很高兴听到其他方法可以做到这一点。
简短回答:
Have written up a few details on what we have found to be best practice so far. You can find it here: http://ben.phegan.name/index.php/2011/02/28/monotouch-and-unit-testing. Would be happy to hear other ways of doing this.
Short answer:
我有同样的问题:
通过进入项目修复 -> [项目名称] 选项->建将军。将编译目标更改为库。我还没有创建 Main-method 类,但可能稍后会创建;那我就改回来。
I had the same problem:
Fixed by going into Project -> [Project name] Options -> Build General. Changed Compile Target to Library. I hadn't made a Main-method class yet, but will probably later; so then I'll change back.