You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "esyimnetz@gmx.de" <es...@gmx.de> on 2012/07/12 02:48:34 UTC

Problem with maven and deleting files in a test case

Hey fellas,
I have a strange problem with Maven and deleting files in a test case.
For a better understanding I reduced my code to the problem parts and
made a small project (maven-file-test, attached to the mail). In this
project there is the class FileUtils with the method "writeFile(File,
String)" which just create a file with a content and a method
"delete(File)" that deletes a file recursively in case of a directory. I
test this class with FileUtilsTest the first test (testWriteFile)
creates the file src/test/resources/file_utils_test/test01 and the
second test (testDeletDir) delete src/test/resources/file_utils_test and
its content . The pom is just a tiny one with no awesome stuff in it.
With JUnit everthing is perfekt on Linux and Windows. With Maven it
works perfekt under Linux, but fails sometimes under Windows 7 64.
I am using Java jdk1.7.0_03 and test it with Maven 2.2.1, 3.0.3, 3.0.4
by calling "mvn clean install" with no success.
I know there is an issue with file handling on Windows that does not
exists on Linux, but wondering that JUnit do the trick and Maven don't
do it (sometimes).
Does anyone knows a solution, if it is a Maven problem?
Thanks,
Bj�rn


Re: Problem with maven and deleting files in a test case

Posted by Wayne Fay <wa...@gmail.com>.
> I see, I made it available on
> http://novaexpress.dyndns.org:8181/maven/maven-file-test.zip for a few days.

I hope you understand when I say that I'm not hugely interested in
downloading and running code that I know 1) deletes stuff and 2)
doesn't seem to work properly in all cases.

But perhaps I will set up a sandbox to test it. Until then, I am just
looking at the pom.xml and other files, and not running them. :)

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problem with maven and deleting files in a test case

Posted by "esyimnetz@gmx.de" <es...@gmx.de>.
>> For a better understanding I reduced my code to the problem parts and
>> made a small project (maven-file-test, attached to the mail). In this
> Just so you know, this mail list strips attachments. If you want to
> share the project, you will need to post it somewhere like Gist.
>
> Wayne
I see, I made it available on
http://novaexpress.dyndns.org:8181/maven/maven-file-test.zip for a few days.
Björn

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problem with maven and deleting files in a test case

Posted by Wayne Fay <wa...@gmail.com>.
> For a better understanding I reduced my code to the problem parts and
> made a small project (maven-file-test, attached to the mail). In this

Just so you know, this mail list strips attachments. If you want to
share the project, you will need to post it somewhere like Gist.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problem with maven and deleting files in a test case

Posted by Stephen Connolly <st...@gmail.com>.
The solution is to use a junit assumption to skip the test, e.g.

Assume.assumeThat("Test fails on windows", System.getProperty("file.seperator.char"), is("/"));

Added to the start of each test method will cause them to be skipped on windows but run elsewhere...

Note I am on my phone and memory is imperfect so the syntax will need tweaking

Sent from my iPhone

On 14 Jul 2012, at 03:42, "esyimnetz@gmx.de" <es...@gmx.de> wrote:

> Am 12.07.2012 23:19, schrieb Wayne Fay:
>>> With JUnit everthing is perfekt on Linux and Windows. With Maven it
>> What version of JUnit and how are you calling it?
>> 
>> 
>>> works perfekt under Linux, but fails sometimes under Windows 7 64.
>> What is the failure under Windows? Can you add code to trap that error
>> and report the details? Do you have any idea why it fails sometimes
>> but not always?
>> 
>> 
>>> I know there is an issue with file handling on Windows that does not
>>> exists on Linux, but wondering that JUnit do the trick and Maven don't
>>> do it (sometimes).
>>> Does anyone knows a solution, if it is a Maven problem?
>> For good measure, I'd suggest adding config to your pom to specify the
>> Surefire version:
>>  <build>
>>    <plugins>
>>      <plugin>
>>        <groupId>org.apache.maven.plugins</groupId>
>>        <artifactId>maven-surefire-plugin</artifactId>
>>        <version>2.12</version>
>>        <dependencies>
>>          <dependency>
>>            <groupId>org.apache.maven.surefire</groupId>
>>            <artifactId>surefire-junit47</artifactId>
>>            <version>2.12</version>
>>          </dependency>
>>        </dependencies>
>>      </plugin>
>>    </plugins>
>>  </build>
>> 
>> Windows is annoying for reasons like this so I try to stay on OSX and
>> Linux whenever possible.
>> 
>> Wayne
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>> 
>> 
> 
> Damn, you made my day!
> Now everything works like I expected.
> 
> Yes,  I understand if you don't want to download and execute code like
> this. It was just a try to bring this thread fast forward. The
> maven-surefire-plugin-hint above was all I needed.
> 
> I did the JUnit tests with version 4.8.1 using eclipse and just hit the
> run button some times with no error. If I
> do it with "mvn clean install" using the command prompt with the
> following pom, I got an error after a few hits on enter.
> 
>    <modelVersion>4.0.0</modelVersion>
>    <groupId>test</groupId>
>    <artifactId>maven-file-test</artifactId>
>    <version>0.0.1-SNAPSHOT</version>
>    <packaging>jar</packaging>
>    <name>maven-file-test</name>
>    <properties>
>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>    </properties>
>    <dependencies>
>        <dependency>
>            <groupId>junit</groupId>
>            <artifactId>junit</artifactId>
>            <version>4.8.1</version>
>            <scope>test</scope>
>        </dependency>
>    </dependencies>
> 
> My code is quite simple. A method that writes a file and another one
> that deletes a file.
> The first test inside the test class writes the file, the second test
> case delete it.
> And I know that it may failed because of the underlying platform like
> the javadoc told, for example, in FileOutputStream.
> After I added a third test case with a loop around writing and deleting
> - which is much as faster as I can do it by pressing the
> run button inside an IDE ;) - and after I added maven-surefire-plugin to
> my pom like you told, I saw that
> both executions (IDE and command prompt) ends with an error.
> With the IDE after a while also and with the command prompt not as often
> as before. The different frequency of the error appearance made me mad.
> 
> The next two questens I have to find out are:
> 1. What does the maven-surefire-plugin exactly do? It still fails, but
> not so much like without it.
> 2. Is there a way to avoid running tests with maven depends on the OS if
> I reach a level where
> no independent solution exists like loading a C-lib for example, don't
> care if it is a good idea?
> 
> Your hint let my go in the right direction again.
> Thanks!
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problem with maven and deleting files in a test case

Posted by "esyimnetz@gmx.de" <es...@gmx.de>.
Am 15.07.2012 01:19, schrieb Wayne Fay:
>> 1. What does the maven-surefire-plugin exactly do? It still fails, but
>> not so much like without it.
> You were already using Surefire, you just had not declared a specific
> version of the plugin to use, so you were probably using an earlier
> version that might have had a bug which is resolved in 2.12, or
> something along those lines.

Ok, I checked this with some more tests playing around with versions.
During these test I fall back in a state where the count of
occurrence of errors differs again. Well, after digging some more, I
think, I know now whats going wrong.
Looks like I was trapped because of an old doctrine: Never use space
charaters in paths!
Maven do everthing well, don't care if I added the surefire snipplet or not.
But eclipse don't do. So further discussions goes to another list. ;)

If someone else is interested, I posted a bug-report at eclipse bugzilla
(ID 385223).
It can be found here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=385223

>> 2. Is there a way to avoid running tests with maven depends on the OS if
>> I reach a level where
>> no independent solution exists like loading a C-lib for example, don't
>> care if it is a good idea?
> Stephen already answered this one. Add code which tests for the OS and
> bails (with a warning) if this test cannot be executed in the current
> OS.

Checked this too. That's what I am looking for and it works perfect
after a little tweaking and customizing.


And for those guys, that reached this thread to get a solution for the
I/O problem, which wasn't part of this thread, should take a look at
package java.nio.file. It is available since 1.7.

Thanks guys!


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problem with maven and deleting files in a test case

Posted by Wayne Fay <wa...@gmail.com>.
> 1. What does the maven-surefire-plugin exactly do? It still fails, but
> not so much like without it.

You were already using Surefire, you just had not declared a specific
version of the plugin to use, so you were probably using an earlier
version that might have had a bug which is resolved in 2.12, or
something along those lines.

> 2. Is there a way to avoid running tests with maven depends on the OS if
> I reach a level where
> no independent solution exists like loading a C-lib for example, don't
> care if it is a good idea?

Stephen already answered this one. Add code which tests for the OS and
bails (with a warning) if this test cannot be executed in the current
OS.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problem with maven and deleting files in a test case

Posted by "esyimnetz@gmx.de" <es...@gmx.de>.
Am 12.07.2012 23:19, schrieb Wayne Fay:
>> With JUnit everthing is perfekt on Linux and Windows. With Maven it
> What version of JUnit and how are you calling it?
>
>
>> works perfekt under Linux, but fails sometimes under Windows 7 64.
> What is the failure under Windows? Can you add code to trap that error
> and report the details? Do you have any idea why it fails sometimes
> but not always?
>
>
>> I know there is an issue with file handling on Windows that does not
>> exists on Linux, but wondering that JUnit do the trick and Maven don't
>> do it (sometimes).
>> Does anyone knows a solution, if it is a Maven problem?
> For good measure, I'd suggest adding config to your pom to specify the
> Surefire version:
>   <build>
>     <plugins>
>       <plugin>
>         <groupId>org.apache.maven.plugins</groupId>
>         <artifactId>maven-surefire-plugin</artifactId>
>         <version>2.12</version>
>         <dependencies>
>           <dependency>
>             <groupId>org.apache.maven.surefire</groupId>
>             <artifactId>surefire-junit47</artifactId>
>             <version>2.12</version>
>           </dependency>
>         </dependencies>
>       </plugin>
>     </plugins>
>   </build>
>
> Windows is annoying for reasons like this so I try to stay on OSX and
> Linux whenever possible.
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Damn, you made my day!
Now everything works like I expected.

Yes,  I understand if you don't want to download and execute code like
this. It was just a try to bring this thread fast forward. The
maven-surefire-plugin-hint above was all I needed.

I did the JUnit tests with version 4.8.1 using eclipse and just hit the
run button some times with no error. If I
do it with "mvn clean install" using the command prompt with the
following pom, I got an error after a few hits on enter.

    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>maven-file-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>maven-file-test</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

My code is quite simple. A method that writes a file and another one
that deletes a file.
The first test inside the test class writes the file, the second test
case delete it.
And I know that it may failed because of the underlying platform like
the javadoc told, for example, in FileOutputStream.
After I added a third test case with a loop around writing and deleting
- which is much as faster as I can do it by pressing the
run button inside an IDE ;) - and after I added maven-surefire-plugin to
my pom like you told, I saw that
both executions (IDE and command prompt) ends with an error.
With the IDE after a while also and with the command prompt not as often
as before. The different frequency of the error appearance made me mad.

The next two questens I have to find out are:
1. What does the maven-surefire-plugin exactly do? It still fails, but
not so much like without it.
2. Is there a way to avoid running tests with maven depends on the OS if
I reach a level where
no independent solution exists like loading a C-lib for example, don't
care if it is a good idea?

Your hint let my go in the right direction again.
Thanks!










---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Problem with maven and deleting files in a test case

Posted by Wayne Fay <wa...@gmail.com>.
> With JUnit everthing is perfekt on Linux and Windows. With Maven it

What version of JUnit and how are you calling it?


> works perfekt under Linux, but fails sometimes under Windows 7 64.

What is the failure under Windows? Can you add code to trap that error
and report the details? Do you have any idea why it fails sometimes
but not always?


> I know there is an issue with file handling on Windows that does not
> exists on Linux, but wondering that JUnit do the trick and Maven don't
> do it (sometimes).
> Does anyone knows a solution, if it is a Maven problem?

For good measure, I'd suggest adding config to your pom to specify the
Surefire version:
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12</version>
        <dependencies>
          <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-junit47</artifactId>
            <version>2.12</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

Windows is annoying for reasons like this so I try to stay on OSX and
Linux whenever possible.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org