Class BaseTestHelper

java.lang.Object
it.tidalwave.util.test.BaseTestHelper
Direct Known Subclasses:
SpringTestHelper

public class BaseTestHelper extends Object
A facility that provides some common tasks for testing, such as manipulating test files.
Since:
3.2-ALPHA-18
Author:
Fabrizio Giudici
  • Field Details

    • test

      @Nonnull protected final Object test
  • Constructor Details

    • BaseTestHelper

      public BaseTestHelper()
  • Method Details

    • resourceFileFor

      @Nonnull public Path resourceFileFor(@Nonnull String resourceName)
      Returns a Path for a resource file. The resource should be placed under src/test/resources/test-class-simple-name/test-resources/resource-name. Note that the file actually loaded is the one under target/test-classes copied there (and eventually filtered) by Maven.
      Parameters:
      resourceName - the resource name
      Returns:
      the Path
    • readStringFromResource

      @Nonnull public String readStringFromResource(@Nonnull String resourceName) throws IOException
      Reads the content from the resource file as a single string. See resourceFileFor(String) for further info.
      Parameters:
      resourceName - the resource name
      Returns:
      the string
      Throws:
      IOException - in case of error
    • testResourceFor

      @Nonnull public BaseTestHelper.TestResource testResourceFor(@Nonnull String resourceName) throws IOException
      Create a BaseTestHelper.TestResource for the given name. The actual file will be created under target/test-artifacts/test-class-simple-name/resourceName. The expected file should be placed in src/test/resources/test-class-simple-name/expected-results/resource-name. Note that the file actually loaded is the one under target/test-classes copied there (and eventually filtered) by Maven. The test-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:
      IOException - in case of error