单元测试 Monotouch

发布于 2024-10-15 08:33:48 字数 1229 浏览 4 评论 0原文

有没有人成功地为他们的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

似狗非友 2024-10-22 08:33:48

您实际上不必创建第二个解决方案,或提取与操作系统无关的代码。不过,有一些技巧。一般情况下:

  1. 引用 MonoTouch 程序集,即使在 .Net 3.5/Mono 测试项目中也是如此
  2. 。 主管控制器模式有助于减少可测试的代码量。

已经写下了一些迄今为止我们发现的最佳实践的细节。您可以在这里找到它: 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:

  1. Reference the MonoTouch assemblies, even in your .Net 3.5/Mono Test Projects
  2. A Supervisor Controller pattern helps with the amount of code you can test.

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.

流殇 2024-10-22 08:33:48

有人成功地为其 Monotouch 项目运行单元测试吗?

是的,最新的 MonoTouch 5.1.x(测试版)版本现在可以实现这一点。

我发现一篇文章说:“..如果您没有在 iPhone 上或 iPhone 模拟器中运行,则无法调用必要的本机 API 来实例化组件..”

确实如此。这就是为什么在 iOS(模拟器或设备)上执行的运行器旨在启用 MonoTouch 相关单元测试的执行。

Has anyone successfully managed to run unit tests for their Monotouch project?

Yes this is now possible with the latest MonoTouch 5.1.x (beta) releases.

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.."

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.

聆听风音 2024-10-22 08:33:48

那是你发现的我的帖子。到目前为止,这是我能做的最好的事情:

  1. 将与操作系统无关的代码提取到单独的库中。
  2. 使用自己的项目文件创建第二个解决方案,将这些库编译为普通 .NET 3.5。
  3. 对库进行单元测试。

从好的方面来说,这鼓励分离您的关注点,并且(理论上)是否可以更轻松地将应用程序移植到 MonoDroid 等。但是保持这两个解决方案同步是一件痛苦的事情,而且当它们不在视线范围内时,很容易偏离实际编写测试的方向。

That was my post you found. So far this is the best I've been able to do:

  1. Pull the OS-agnostic code out into separate libraries.
  2. Create a second solution, with its own project files, to compile those libraries as vanilla .NET 3.5.
  3. Unit-test the libraries.

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.

老旧海报 2024-10-22 08:33:48

是的,这是可能的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文