开发者

junit testing a class with shell scripting functionality under win32

We have an API which is used in a class via a开发者_JAVA百科n 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜