tags:

views:

196

answers:

2

Hi,

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.

+1  A: 

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.

sleske
thanks, the list of actions looks solid. To clarify, I do not have any win32 platform-specific functionality. See update.
D_K
A: 

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.

Pascal Thivent
thanks for the cygwin option.Empty script in PATH by sleske sounds also elegant. OTOH, running the proper sh script may be required for the business logic (depends on how deep I go with the unit testing).
D_K
by the way, there is cygwin installed on my win32 pc, but how can I run my unit tests via Eclipse? Isn't so, that I should be running them under cygwin shell?
D_K
I can't do much testing as I'm not under windows but if I remember well, cygwin commands are available in a windows shell (cmd), aren't they? What problem do you get under eclipse?
Pascal Thivent
Pascal Thivent:IO Exception caught when getting RCFILE: Cannot run program "/bin/sh": CreateProcess error=3, The system cannot find the path specified
D_K
Well, I guess that you have to run them under cygwin shell.
Pascal Thivent