9

I am facing a weird problem here...

I have a JUnit implementing a few tests. This class looks like the following:

public class MyTest {

    @Rule
    public TemporaryFolder folder = new TemporaryFolder();

    @Test
    public void myTest1() throws IOException {
        String destinationPath = folder.newFile("destination1.txt").getPath();
        // Do things
    }

    @Test
    public void myTest2() throws IOException {
        String destinationPath = folder.newFile("destination2.txt").getPath();
        // Do things
    }

    @Test
    public void myTest3() throws IOException {
        String destinationPath = folder.newFile("destination.txt").getPath();
        // Do things
    }
}

This test class used to work in my previous environment and still does in Continuum.

Yet, when launching from Eclipse none, some, or all of the tests arbitrarily throw an IOException such as:

java.io.IOException: The system cannot find the path specified
    at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    at java.io.File.createNewFile(File.java:883)
    at org.junit.rules.TemporaryFolder.newFile(TemporaryFolder.java:53)
    at MyTest.myTest2(MyTest.java:50)

I have the exact same problem running JUnit 4.9 or JUnit 4.10 ...

How can I fix that so that it works properly?

nattyddubbs
  • 2,085
  • 15
  • 24
Jean Logeart
  • 52,687
  • 11
  • 83
  • 118
  • That should work. Which `Runner` are you using to run the tests? Are they concurrent? You might want to debug more, i.e. sout the `folder` variable too see where it points when the problem occurs. – Petr Janeček Apr 17 '12 at 18:38
  • Can you say what you're doing in the tests? Are you writing to the files? Also, do you have windows indexation running? – Matthew Farwell May 30 '12 at 06:45
  • Yes the aim of the program is to process data and to write a file as output. No windows indexation is running. – Jean Logeart May 30 '12 at 07:10

3 Answers3

1

You should try disabling your anti-virus protection.

I was having same problem, and after disabling Kaspersky everything was working just fine.

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
Kamil
  • 26
  • 1
0

By the looks of it, this might be more a windows related problem than a JUnit one. Somehow, you could be missing the right to create folders/files while being logged in as a "limited rights user".

I guess you could try creating a temporary folder yourslef, just as JUnit does:

        File folder= File.createTempFile("junit", "");

If the statement above throws the same error, you should investigate your windows user rights, maybe try running the test under a "full-rights" user.

Morfic
  • 15,178
  • 3
  • 51
  • 61
0

What seemed to help in my case was explicitly creating the root folder; in your case, throwing a folder.create() somewhere into your code.

Ugly, I know.

buer
  • 330
  • 4
  • 11