Class MavenTestingUtils
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FileObtain aFilereference to the maven ${basedir} for the module.static PathObtain aPathreference to the maven ${basedir} for the module.static URIGet the Basedir for the project as a URIstatic FilegetProjectDir(String path) Get a directory reference to a required directory in the project module path, based on relative path references from maven ${basedir}.static PathgetProjectDirPath(String path) Get aPathreference to a required directory in the project module path, based on relative path references from maven ${basedir}.static FilegetProjectFile(String path) Get aFilereference to a required file in the project module path, based on relative path references from maven ${basedir}.static PathgetProjectFilePath(String path) Get aPathreference to a required file in the project module path, based on relative path references from maven ${basedir}.static FileGet theFilereference to the/targetdirectory for this project.static FilegetTargetFile(String path) Create aFileobject for a path in the /target directory.static PathGet thePathreference to the/targetdirectory for this project.static PathgetTargetPath(String path) Create aPathobject for a path in the /target directory.static FileGet aFilereference to the maven${basedir}/target/tests/directory.static FilegetTargetTestingDir(Class<?> testclass, String testmethodname) Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.static FilegetTargetTestingDir(String testname) Get aFilereference to the maven${basedir}/target/tests/test-${testname}using the supplied testnamestatic FilegetTargetTestingDir(junit.framework.TestCase test) Get aFilereference to the${basedir}/target/tests/test-${testname}directory.static PathGet aPathreference to the maven${basedir}/target/tests/path.static PathgetTargetTestingPath(Class<?> testclass, String testmethodname) Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.static PathgetTargetTestingPath(String testname) Get aPathreference to the maven${basedir}/target/tests/test-${testname}using the supplied testnamestatic PathgetTargetTestingPath(junit.framework.TestCase test) Get aPathreference to the${basedir}/target/tests/test-${testname}directory.static URIgetTargetURI(String path) Get a URI reference to a path (File or Dir) within the maven "${basedir}/target" directory.static URLgetTargetURL(String path) Get a URL reference to a path (File or Dir) within the maven "${basedir}/target" directory.private static MavenTestingUtils.TestIDUsing junit 3.x naming standards for unit tests and test method names, attempt to discover the unit test name from the execution stack.static FilegetTestResourceDir(String name) Get a dir from the maven${basedir}/src/test/resourcedirectory.static FilegetTestResourceFile(String name) Get a file from the maven${basedir}/src/test/resourcedirectory.static PathgetTestResourcePath(String name) Get a path resource (File or Dir) from the maven${basedir}/src/test/resourcedirectory.static PathgetTestResourcePathDir(String name) Get a dir from the maven${basedir}/src/test/resourcedirectory.static PathGet a file from the maven${basedir}/src/test/resourcedirectory.static FileGet theFilereference to the maven${basedir}/src/test/resourcesdirectorystatic PathGet thePathreference to the maven${basedir}/src/test/resourcesdirectory
-
Field Details
-
basePath
-
testResourcesPath
-
targetPath
-
-
Constructor Details
-
MavenTestingUtils
private MavenTestingUtils()
-
-
Method Details
-
getBaseDir
-
getBasePath
Obtain aPathreference to the maven ${basedir} for the module.Note: while running in maven, the ${basedir} is populated by maven and used by the surefire-plugin.
While running in eclipse, the ${basedir} property is unset, resulting in this method falling back to ${user.dir} equivalent use.- Returns:
- the equivalent to the maven ${basedir} property.
-
getBaseURI
Get the Basedir for the project as a URI- Returns:
- the URI for the project basedir
-
getTargetDir
-
getTargetPath
Get thePathreference to the/targetdirectory for this project.This is roughly equivalent to the
${project.build.directory}property.Note: this implementation does not inspect the
pom.xmlfor non-standard locations of the${project.build.directory}property. (it always assumes/target)- Returns:
- the directory path to the
/targetdirectory.
-
getTargetFile
-
getTargetPath
-
getTargetTestingDir
Get aFilereference to the maven${basedir}/target/tests/directory.Convenience method for
MavenTestingUtils.getTargetTestingPath().toFile()- Returns:
- the maven
${basedir}/target/tests/directory. Note: will not validate that the directory exists, or create the directory)
-
getTargetTestingPath
-
getTargetTestingDir
Get aFilereference to the maven${basedir}/target/tests/test-${testname}using the supplied testnameConvenience method for
MavenTestingUtils.getTargetTestingPath(testname).toFile()- Parameters:
testname- the testname to create directory against.- Returns:
- the maven
${basedir}/target/tests/test-${testname}directory
-
getTargetTestingPath
-
getTargetTestingDir
Get aFilereference to the${basedir}/target/tests/test-${testname}directory. Uses the JUnit 3.xTestCase.getName()to make a unique directory name per test.Convenience method for
MavenTestingUtils.getTargetTestingPath(TestCase.getName()).toFile()- Parameters:
test- the junit 3.x testcase to base this new directory on.- Returns:
- the maven
${basedir}/target/tests/test-${testname}directory.
-
getTargetTestingPath
Get aPathreference to the${basedir}/target/tests/test-${testname}directory. Uses the JUnit 3.xTestCase.getName()to make a unique directory name per test.Convenience method for
MavenTestingUtils.getTargetTestingPath(TestCase.getName())- Parameters:
test- the junit 3.x testcase to base this new directory on.- Returns:
- the maven
${basedir}/target/tests/test-${testname}directory. - See Also:
-
getTargetURI
-
getTargetURL
Get a URL reference to a path (File or Dir) within the maven "${basedir}/target" directory.Convenience method for
MavenTestingUtils.getTargetURI(path).toURL()- Parameters:
path- the relative path to use- Returns:
- the URL reference to the target path
- Throws:
MalformedURLException- if unable to create a new target url due to URL error.
-
getTargetTestingDir
Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.Note: the @Rule
TestingDiris a better choice in most cases.Convenience method for
MavenTestingUtils.getTargetTestingDir(testclass, testmethodname).toFile()- Parameters:
testclass- the class for the test casetestmethodname- the test method name- Returns:
- the File path to the testname specific testing directory underneath the
${basedir}/target/tests/sub directory - See Also:
-
getTargetTestingPath
Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.Note: the @Rule
TestingDiris a better choice in most cases.- Parameters:
testclass- the class for the test casetestmethodname- the test method name- Returns:
- the File path to the testname specific testing directory underneath the
${basedir}/target/tests/sub directory - See Also:
-
getProjectFile
Get aFilereference to a required file in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing file
Convenience method for
MavenTestingUtils.getProjectFilePath(path).toFile()- Parameters:
path- the relative path to reference- Returns:
- the file reference (must exist)
-
getProjectFilePath
Get aPathreference to a required file in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing file
- Parameters:
path- the relative path to reference- Returns:
- the file reference (must exist)
-
getProjectDir
Get a directory reference to a required directory in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing directory
Convenience method for
MavenTestingUtils.getProjectDirPath(path).toFile()- Parameters:
path- the relative path to reference- Returns:
- the directory reference (must exist)
-
getProjectDirPath
Get aPathreference to a required directory in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing directory
- Parameters:
path- the relative path to reference- Returns:
- the directory reference (must exist)
-
getTestID
Using junit 3.x naming standards for unit tests and test method names, attempt to discover the unit test name from the execution stack.- Returns:
- the unit test id found via execution stack and junit 3.8 naming conventions.
- See Also:
-
getTestResourcesDir
-
getTestResourcesPath
-
getTestResourceDir
Get a dir from the maven${basedir}/src/test/resourcedirectory.Note: will throw assertion error if path does point to an existing directory
Convenience method for
MavenTestingUtils.getTestResourcesPathDir(name).toFile()- Parameters:
name- the name of the path to get (it must exist as a dir)- Returns:
- the dir in the maven
${basedir}/src/test/resourcepath
-
getTestResourcePathDir
Get a dir from the maven${basedir}/src/test/resourcedirectory.Note: will throw assertion error if path does point to an existing directory
- Parameters:
name- the name of the path to get (it must exist as a dir)- Returns:
- the dir in the maven
${basedir}/src/test/resourcepath
-
getTestResourceFile
Get a file from the maven${basedir}/src/test/resourcedirectory.Note: will throw assertion error if path does point to an existing file
- Parameters:
name- the name of the path to get (it must exist as a file)- Returns:
- the file in maven
${basedir}/src/test/resource
-
getTestResourcePathFile
Get a file from the maven${basedir}/src/test/resourcedirectory.Note: will throw assertion error if path does point to an existing file
- Parameters:
name- the name of the path to get (it must exist as a file)- Returns:
- the file in maven
${basedir}/src/test/resource
-
getTestResourcePath
-