junit 在 win32 下测试具有 shell 脚本功能的类

发布于 2024-08-14 00:03:16 字数 485 浏览 5 评论 0原文

我们有一个 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 技术交流群。

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

发布评论

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

评论(2

单身情人 2024-08-21 00:03:16

你的问题不清楚。显然,如果代码适用于 Unix,则它无法在 Win32 下运行,因此单元测试失败是很自然的(也是正常的)。为什么要在 Win32 下测试适用于 Unix 的代码?

如果你无法在 Unix 下测试(或者重写代码使其与平台无关),一些选项是:

  • 重构代码以不直接访问 /bin/Sh;然后你可以模拟依赖关系以获得真正的单元测试,该测试将是独立于平台的(请注意,严格来说,依赖于 /bin/sh 等外部资源的测试不是单元测试,而是集成测试)
  • 安装某种类型Win32 上的虚拟脚本取代 /bin/sh (并且可能使路径可配置,
  • 将 junit 测试列表拆分为平台相关和独立的测试,并且仅在 Win32 下运行在那里工作的测试(其余的在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:

  • Refactor the code to not directly access /bin/Sh; then you can mock the dependency to get a true Unit test, which will be platform independent (note that strictly speaking a test that depends on external resources like /bin/sh is not a unit test, but an integration test)
  • install some kind of dummy script on Win32 to take the place of /bin/sh (and possibly make the path configurable
  • split your list of junit tests into platform-dependent and -independent tests, and only run the tests under Win32 that work there (and the rest on Unix)

But you really should clear up first how you want to test your platform-specific functionality.

萧瑟寒风 2024-08-21 00:03:16

这是第 22 条军规的情况还是有机会解决?

如果可以的话,如果您的代码不适合移植(我不会讨论这一点),那么您为什么要在 Windows 上构建它?也许您可以添加平台检查,以避免在 Windows 上运行时调用“Unix”API。或者,也许您可​​以安装 cygwin 以使 sh 在 Windows 上也可用。

也许除了 junit 之外还存在一些可以在 UNIX 下轻松运行的框架。谢谢。

啊?也许我没明白,但我的理解是你的代码有问题,而不是 JUnit。如果我错了,请澄清你的期望。

Is it a catch-22 situation or there is a chance to work it out?

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.

Maybe some framework other than junit exists that can be easily run under UNIX. Thanks.

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.

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