JUnit TemporaryFolder Rule arbitrarily throws an IOException

I had a strange problem ...

I have a JUnit that implements several tests. This class is as follows:

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 was used to work in my previous environment and still works in Continuum.

However, when starting from Eclipse, none, none, or all tests arbitrarily throw an IOException , for example:

 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 same problem with running JUnit 4.9 or JUnit 4.10 ...

How can I fix this so that it works correctly?

+8
java junit junit4 ioexception
source share
2 answers

You should try disabling anti-virus protection.

I had the same problem, and after disabling Kaspersky everything worked fine.

+1
source share

In appearance, this may be more of a window-related issue than JUnit. One way or another, you may not have the right to create folders / files when logging in as a "user with limited rights."

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

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

If the above statement produces the same error, you should examine the user rights on your Windows, perhaps try running the test as a user with full rights.

0
source share

All Articles