Package it.tidalwave.util.test
Class BaseTestHelper
- java.lang.Object
-
- it.tidalwave.util.test.BaseTestHelper
-
- Direct Known Subclasses:
SpringTestHelper
public class BaseTestHelper extends java.lang.Object
A facility that provides some common tasks for testing, such as manipulating test files.- Since:
- 3.2-ALPHA-18
- Author:
- Fabrizio Giudici
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BaseTestHelper.TestResource
A manipulator of a pair of (actual file, expected file).
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Object
test
-
Constructor Summary
Constructors Constructor Description BaseTestHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
readStringFromResource(java.lang.String resourceName)
Reads the content from the resource file as a single string.java.nio.file.Path
resourceFileFor(java.lang.String resourceName)
Returns aPath
for a resource file.BaseTestHelper.TestResource
testResourceFor(java.lang.String resourceName)
Create aBaseTestHelper.TestResource
for the given name.
-
-
-
Method Detail
-
resourceFileFor
@Nonnull public java.nio.file.Path resourceFileFor(@Nonnull java.lang.String resourceName)
Returns aPath
for a resource file. The resource should be placed undersrc/test/resources/test-class-simple-name/test-resources/resource-name
. Note that the file actually loaded is the one undertarget/test-classes
copied there (and eventually filtered) by Maven.- Parameters:
resourceName
- the resource name- Returns:
- the
Path
-
readStringFromResource
@Nonnull public java.lang.String readStringFromResource(@Nonnull java.lang.String resourceName) throws java.io.IOException
Reads the content from the resource file as a single string. SeeresourceFileFor(String)
for further info.- Parameters:
resourceName
- the resource name- Returns:
- the string
- Throws:
java.io.IOException
- in case of error
-
testResourceFor
@Nonnull public BaseTestHelper.TestResource testResourceFor(@Nonnull java.lang.String resourceName) throws java.io.IOException
Create aBaseTestHelper.TestResource
for the given name. The actual file will be created undertarget/test-artifacts/test-class-simple-name/resourceName
. The expected file should be placed insrc/test/resources/test-class-simple-name/expected-results/resource-name
. Note that the file actually loaded is the one undertarget/test-classes
copied there (and eventually filtered) by Maven. Thetest-class-simple-name
is tried first with the current test, and then with its eventual super-classes; this allows to extend existing test suites. Note that if the resource files for a super class are not in the current project module, they should be explicitly copied here (for instance, by means of the Maven dependency plugin).- Parameters:
resourceName
- the name- Returns:
- the
TestResource
- Throws:
java.io.IOException
- in case of error
-
-