单元测试 Monotouch
有没有人成功地为他们的 Monotouch 项目运行单元测试? 我读过其他帖子,其中告诉人们手动添加对适当程序集的引用。 这样做可以使项目编译,但仍然不会运行测试。
我有两个项目的解决方案; Monotouch 导航项目和 NUnit 库项目。 我添加了对我的单触摸项目以及测试项目中的单触摸和其他所需程序集的引用。 仅在单触摸程序集外部运行代码的测试将运行良好,访问单触摸代码的测试将失败并显示:
System.IO.IOException:写入失败---> System.Net.Sockets.SocketException:套接字已关闭 在 System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 偏移量, Int32 大小, SocketFlags 标志) [0x00000] 中:0 在 System.Net.Sockets.NetworkStream.Write (System.Byte[] 缓冲区,Int32 偏移量,Int32 大小) [0x00000] 中:0 --- 内部异常堆栈跟踪结束 --- 在 System.Net.Sockets.NetworkStream.Write (System.Byte[] 缓冲区,Int32 偏移量,Int32 大小) [0x00000] 中:0 在 System.IO.BufferedStream.Flush () [0x00000] 中:0 at(包装器远程调用带检查)System.IO.BufferedStream:Flush () 在 System.IO.BufferedStream.Dispose (布尔处置)[0x00000] 中:0 在 System.IO.Stream.Close () [0x00000] 中:0 在 Mono.Remoting.Channels.Unix.ClientConnection.ProcessMessages () [0x00000] 中:0
我发现 一篇文章说: “......如果你没有在 iPhone 上或 iPhone 模拟器中运行,则无法调用必要的本机 API 来实例化组件......”
所以我真正想知道的是是否真的可以做到目前在 Monotouch 中进行单元测试,或者如果没有,你们其他人都在做什么?
谢谢!
Has anyone successfully managed to run unit tests for their Monotouch project?
I have read other posts where people are told to manually add references to the appropriate assemblies.
Doing this makes the project compile, but it will still not run the tests.
I have a solution with two projects; a Monotouch Navigation project and an NUnit Library Project.
I added a reference to my monotouch project and to the monotouch and other needed assemblies to the test project.
Tests that only runs code outside the monotouch assembly will run fine, the ones that accesses monotouch code fails with:
System.IO.IOException: Write failure ---> System.Net.Sockets.SocketException: The socket has been shut down
at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags) [0x00000] in :0
at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in :0
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in :0
at System.IO.BufferedStream.Flush () [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.IO.BufferedStream:Flush ()
at System.IO.BufferedStream.Dispose (Boolean disposing) [0x00000] in :0
at System.IO.Stream.Close () [0x00000] in :0
at Mono.Remoting.Channels.Unix.ClientConnection.ProcessMessages () [0x00000] in :0
I found a post saying:
"..if you're not running on the iPhone or in the iPhone simulator, there's no way to call the necessary native APIs to instantiate the components.."
So what I´m really wondering is if it´s actually possible to do unit testing in Monotouch at the moment, or if not, what all you other guys do?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您实际上不必创建第二个解决方案,或提取与操作系统无关的代码。不过,有一些技巧。一般情况下:
已经写下了一些迄今为止我们发现的最佳实践的细节。您可以在这里找到它: http://ben .phegan.name/index.php/2011/02/28/monotouch-and-unit-testing。
You don't actually have to create a second solution, or pull out OS-agnostic code. There are a few tricks to it though. Generally:
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.
是的,最新的 MonoTouch 5.1.x(测试版)版本现在可以实现这一点。
确实如此。这就是为什么在 iOS(模拟器或设备)上执行的运行器旨在启用 MonoTouch 相关单元测试的执行。
Yes this is now possible with the latest MonoTouch 5.1.x (beta) releases.
That's true. This is why a runner, executing on iOS (simulator or devices), was built to enable the execution of MonoTouch related unit tests.
那是你发现的我的帖子。到目前为止,这是我能做的最好的事情:
从好的方面来说,这鼓励分离您的关注点,并且(理论上)是否可以更轻松地将应用程序移植到 MonoDroid 等。但是保持这两个解决方案同步是一件痛苦的事情,而且当它们不在视线范围内时,很容易偏离实际编写测试的方向。
That was my post you found. So far this is the best I've been able to do:
On the bright side, this encourages separating your concerns and (in theory) should it easier to port the app to, say, MonoDroid. But keeping the two solutions in sync is a pain, and it's easy to drift away from actually writing tests when they're out of sight.
是的,这是可能的。
Xamarin 文档团队添加了关于使用内置单元的文档测试模板,它使用 NUnitLite 项目的修改版本进行操作。
Yes, it is possible.
The Xamarin Docs Team has added a document on using the built-in unit tests template, which operates using a modified version of the NUnitLite project.