diff --git a/src/test/java/emissary/test/core/junit5/RegressionTest.java b/src/test/java/emissary/test/core/junit5/RegressionTest.java index 7351eddcd8..e29670165d 100644 --- a/src/test/java/emissary/test/core/junit5/RegressionTest.java +++ b/src/test/java/emissary/test/core/junit5/RegressionTest.java @@ -60,7 +60,7 @@ public abstract class RegressionTest extends ExtractionTest { * automatically */ @ForOverride - protected boolean generateAnswers() { + protected static boolean generateAnswers() { return Boolean.getBoolean("generateAnswers"); } diff --git a/src/test/java/emissary/test/core/junit5/RegressionTestUtil.java b/src/test/java/emissary/test/core/junit5/RegressionTestUtil.java index 137b01d61b..a03b631bb3 100644 --- a/src/test/java/emissary/test/core/junit5/RegressionTestUtil.java +++ b/src/test/java/emissary/test/core/junit5/RegressionTestUtil.java @@ -95,6 +95,13 @@ public final class RegressionTestUtil { */ private static final Path TEST_RESX = getTestResx(); + /** + * Used for RegressionTest generateAnswer when {@link UnitTest#getMyTestParameterFiles(Class, Class)} has two different + * classes, and we need to generate answer files in the ansClass directory + */ + @Nullable + private static String ansClass = null; + private RegressionTestUtil() {} /** @@ -200,7 +207,14 @@ public static Path getXmlPath(final String resource) { return null; } - final String xmlPath = resource.substring(0, datPos) + ResourceReader.XML_SUFFIX; + String xmlPath; + if (ansClass == null) { + xmlPath = resource.substring(0, datPos) + ResourceReader.XML_SUFFIX; + } else { + String ansPath = ansClass.replace(".", "/"); + int testNamePos = resource.lastIndexOf("/"); + xmlPath = ansPath + resource.substring(testNamePos, datPos) + ResourceReader.XML_SUFFIX; + } return TEST_RESX.resolve(xmlPath); } @@ -350,4 +364,8 @@ public static void tweakFinalIbdoWithFormInFilename(final String resource, final fail("Couldn't get path for resource: " + resource, e); } } + + public static void setAnsClass(String ansClass) { + RegressionTestUtil.ansClass = ansClass; + } } diff --git a/src/test/java/emissary/test/core/junit5/UnitTest.java b/src/test/java/emissary/test/core/junit5/UnitTest.java index fdc5d5c0a5..59b55a1605 100644 --- a/src/test/java/emissary/test/core/junit5/UnitTest.java +++ b/src/test/java/emissary/test/core/junit5/UnitTest.java @@ -148,6 +148,11 @@ public static Stream getMyTestParameterFiles(Class clz) * @return the stream of test resource files to be used for JUnit Parameterized Tests */ public static Stream getMyTestParameterFiles(Class dataClz, Class ansClz) { + // check to see if answers need to be generated in ansClass directory + if (!dataClz.getName().equals(ansClz.getName()) && RegressionTest.generateAnswers()) { + RegressionTestUtil.setAnsClass(ansClz.getName().replace(".", "/")); + } + ResourceReader rr = new ResourceReader(); List rs = rr.findDataResourcesFor(dataClz); answerFiles = getMyTestAnswerFiles(rr, ansClz);