パッケージ com.kazurayam.unittest
クラス TestOutputOrganizer
java.lang.Object
com.kazurayam.unittest.TestOutputOrganizer
Provides utility methods that helps JUnit4/JUnit5/TestNG tests with
the getProjectDirViaClasspath() method and the resolveOutput().
These methods are useful for Gradle Multi-projects where
the Current Working Directory is NOT equal to the sub-projects' root directory.
-
ネストされたクラスの概要
修飾子とタイプクラス説明static class
Joshua Bloch's "Builder" for the TestOutputOrganizer class -
メソッドの概要
修飾子とタイプメソッド説明cleanMethodOutputDirectory
(Method testMethod) cleanMethodOutputDirectory
(String testMethodName) remove the output directory recursively if it is already present.remove the directory, which is identifiable by outputDir.resolve(subDirPath), recursively if it is already present.void
copy the source directory and its content files/directories to the target directory recursively.createMethodOutputDirectory
(Method testMethod) createMethodOutputDirectory
(String testMethodName) void
delete the target directory and its content files/directories recursively.resolveMethodOutputDirectory
(Method testMethod) resolveMethodOutputDirectory
(String testMethodName) if the subDirPath is set by setSubDir(Path d), then will return getOutputDir().resolve(subDirPath) if the subDirpath is not set, then will return the same as getOutputDir()toHomeRelativeString
(Path path) This method is meant to be used in messages and documentations.
-
メソッドの詳細
-
getProjectDirectory
- 戻り値:
- the project directory where the clazz is hosted
-
getOutputDirectoryPathRelativeToProject
- 戻り値:
- a String like "build/tmp/testOutput" which was given to the Builder.
-
resolveOutputDirectory
- 戻り値:
- returns the java.nio.file.Path object of the output directory. The default is "(projectDir)/test-output". You can customize the name of the output directory by calling setOutputDir(Path.get("dirName")), which is relative to the project directory.
-
createOutputDirectory
- 例外:
IOException
-
cleanOutputDirectory
remove the output directory recursively if it is already present. will re-create the output directory, which will be empty- 戻り値:
- the reference to this TestOutputOrganizer instance
- 例外:
IOException
- during removing files/directories
-
getOutputSubDirectoryPath
-
resolveSubOutputDirectory
if the subDirPath is set by setSubDir(Path d), then will return getOutputDir().resolve(subDirPath) if the subDirpath is not set, then will return the same as getOutputDir()- 戻り値:
- Path of output sub directory
-
createSubOutputDirectory
- 例外:
IOException
-
cleanSubOutputDirectory
remove the directory, which is identifiable by outputDir.resolve(subDirPath), recursively if it is already present. Will re-create the dir which will be empty.- 戻り値:
- the reference to this TestOutputOrganizer instance
- 例外:
IOException
- during removing files/directories
-
resolveClassOutputDirectory
-
createClassOutputDirectory
- 例外:
IOException
-
cleanClassOutputDirectory
- 例外:
IOException
-
resolveMethodOutputDirectory
-
resolveMethodOutputDirectory
-
createMethodOutputDirectory
- 例外:
IOException
-
createMethodOutputDirectory
- 例外:
IOException
-
cleanMethodOutputDirectory
- 例外:
IOException
-
cleanMethodOutputDirectory
- 例外:
IOException
-
toHomeRelativeString
This method is meant to be used in messages and documentations. You do not want to show your own personal name in the console messages, right? So you will surely want to hide the username part of paths. This method translate a Path of "/User/kazurayam/github/unittest-helper/app/foo.txt" to "~/github/unittest-helper/app/foo.txt" which is relative to the $HOME of the user if the path is located under the $HOME. If the path is NOT located under the $HOME, just stringify the absolute path. This method returns a strin in the UNIX style path representation separated with '/' charactor even on Windows platform.- パラメータ:
path
- a Path object to be translated into a Home Relative path string- 戻り値:
- a path string prepended by tilde `~` if the path starts with "user.home"
-
copyDir
copy the source directory and its content files/directories to the target directory recursively. If the targetDir is not existing, will create it.- パラメータ:
sourceDir
- directory to copy fromtargetDir
- directory to copy into- 例外:
IOException
- any error while i/o
-
deleteDir
delete the target directory and its content files/directories recursively.- パラメータ:
targetDir
- directory to delete- 例外:
IOException
- any error while deletion
-