junit 在 win32 下测试具有 shell 脚本功能的类
我们有一个 API,通过公开的接口在类中使用。该 API 适用于 UNIX 系列,并假设每个 UNIX 都有 /bin/sh。因此,当在 win32 下运行 junit 测试时,我们得到:
Cannot run program "/bin/sh"
这是一个 catch-22 情况还是有机会解决它?也许除了 junit 之外还存在一些可以在 UNIX 下轻松运行的框架。谢谢。
更新:
代码是可移植的并且可以在多个操作系统(java)上运行。 我想编写一些单元测试(这是我自己的倡议),部分代码作为api暴露给我(正在另一个部门测试)。现在,当我对自己的代码运行测试时,由于它依赖于 api 代码,因此它会在后面执行一些魔法,例如调用 shell 脚本,这些脚本在原始 win32 下不存在(我们使用 win32+ssh 进行开发)。
目前还不能选择切换到 Linux。 通过 nx 客户端将 Eclipse 安装到 unix + gui 上也是一种选择。希望它能澄清一点。
We have an API which is used in a class via an exposed interface. The API is meant for UNIX family and assumes, that every UNIX has /bin/sh. Thus when running the junit test under win32 we get:
Cannot run program "/bin/sh"
Is it a catch-22 situation or there is a chance to work it out? Maybe some framework other than junit exists that can be easily run under UNIX. Thanks.
update:
The code is portable and meant to be run on several OSes (java).
I want to write some unit tests (which is my own initiative) and parts of code are exposed to me as apis (being tested in another department). Now when I run tests for my own code, since it is dependent on the apis code it does some magic behind, like calling shell scripts, which do not exist under virgin win32 (we do our development using win32+ssh).
Switching to Linux is not an option at the moment.
Installing Eclipse onto unix + gui via nx client can be an option though. Hope it clarifies a bit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题不清楚。显然,如果代码适用于 Unix,则它无法在 Win32 下运行,因此单元测试失败是很自然的(也是正常的)。为什么要在 Win32 下测试适用于 Unix 的代码?
如果你无法在 Unix 下测试(或者重写代码使其与平台无关),一些选项是:
但是您确实应该首先明确要如何测试特定于平台的功能。
Your question is unclear. Obviously, if the code is meant for Unix it will not work under Win32, so it's natural (and OK) for the unit test to fail. Why are you testing code meant for Unix under Win32?
If you cannot test under Unix (or rewrite the code to be platform-independent), some options would be:
But you really should clear up first how you want to test your platform-specific functionality.
如果可以的话,如果您的代码不适合移植(我不会讨论这一点),那么您为什么要在 Windows 上构建它?也许您可以添加平台检查,以避免在 Windows 上运行时调用“Unix”API。或者,也许您可以安装 cygwin 以使
sh
在 Windows 上也可用。啊?也许我没明白,但我的理解是你的代码有问题,而不是 JUnit。如果我错了,请澄清你的期望。
If I may, if your code isn't mean to be portable (I won't discuss this), why do you build it on Windows? Maybe you could add a check of the platform to avoid calling the "Unix" API when running on Windows though. Or maybe you could install cygwin to make
sh
available on Windows too.Huh? Maybe I didn't get it but my understanding is that you have a problem with your code, not with JUnit. Please clarify your expectations if I'm wrong.