Project Testing: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 79: Line 79:
         //
         //


         assertTrue(io.novaordis.utilities.Files.rmdir(new File(System.getProperty("basedir"), "target/test-scratch"), true));
         assertTrue(io.novaordis.utilities.Files.rmdir(new File(System.getProperty("basedir"), "target/test-scratch"), false));


     }
     }

Revision as of 05:53, 31 July 2016

Internal

Testing Files in the Scratch Area of the Project

Maven Configuration


...

<properties>
    <test.scratch.directory>target/test-scratch</test.scratch.directory>
</properties>

Note that the below section must be declared under the <plugins> and not <pluginManagement>:

...

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <dependencies>
                 <dependency>
                     <groupId>org.apache.ant</groupId>
                     <artifactId>ant</artifactId>
                     <version>1.7.0</version>
                  </dependency>
              </dependencies>
              <executions>
                  <execution>
                      <phase>generate-test-resources</phase>
                               <configuration>
                          <tasks>
                              <mkdir dir="${test.scratch.directory}" />
                          </tasks>
                      </configuration>
                      <goals>
                          <goal>run</goal>
                      </goals>
                 </execution>
             </executions>
         </plugin>
    </plugins>
   ...
</build>

Code

Access from Test

String projectBaseDirName = System.getProperty("basedir");
File testScratchDir = new File(projectBaseDirName, "target/test-scratch");
assertTrue(testScratchDir.isDirectory());

...

Cleanup after Test


    ...

    @After
    public void after() throws Exception {
        
        //
        // scratch directory cleanup
        //

        assertTrue(io.novaordis.utilities.Files.rmdir(new File(System.getProperty("basedir"), "target/test-scratch"), false));

    }

    ...