Dred
Dred

Reputation: 1120

maven-failsafe-plugin starts test from wrong classpath

I have multimodule project where in child pom I have traditional maven-failsafe-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.11</version>
    <executions>
      <execution>
        <goals>
          <goal>integration-test</goal>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

But I have dependecy of another test like

<dependency>
        <groupId>my.project.group</groupId>
        <artifactId>core</artifactId>
        <version>1.0-SNAPSHOT</version>
        <scope>test</scope>
</dependency>
<dependency>
        <groupId>my.project.group</groupId>
        <artifactId>core</artifactId>
        <version>1.0-SNAPSHOT</version>
        <classifier>test</classifier>
        <type>test-jar></type>
        <scope>test</scope>
</dependency>

When I start test through IDEA like right mouse clieck on the test`s folder and Run 'All Test' my test start and finish as I want. Byt when I start with mvn clean veryfy -Pit where is it my profile for integration-test It starts good but it looks resources not in {basedir}/target/classes and I get

FileNotFoundException: file:\C:\Users\User\AppData\Local\Temp\surefire1195270631651299000..%5C..%5C..%5C..%5C..%5C..%5Crepos%5CMyProject%5Ccore%5Ctarget%5Ccore-1.0-SNAPSHOT-tests.jar!\csv\dict\V_DICT_USEDDATE_CODE

Why?

PS. Add more information:

In my integration-test I have test like in integration-test/src/test/java

@TestInstance(Lifecycle.PER_CLASS)
@ExtendWith(MockitoExtension.class)
public class ContextTest {


    @SneakyThrows
    public static CalcDBService getInstance() {
        CalcDBService serviceLocal = new CalcDBService();
        ...
        setField(serviceLocal, DictionaryServiceTest.getInstance(), "dictionaryService");
        ...
        return serviceLocal;
    }

    @SneakyThrows
    public static void setField(Object instance, Object value, String fieldName) {
        final Field field = getField(instance, fieldName);
        field.set(instance, value);
    }

Here DictionaryServiceTest from core/srv/test/java

So, inside core we can found

public class DictionaryServiceTest {
// fullpath is core/src/test/resources/csv/dict/V_DICT_USEDDATE_CODES.csv
    public static final String CSV_DICT_CODES = "dict/V_DICT_CODES.csv";

    public static DictionaryService getInstance() throws ReflectiveOperationException {

        DictionaryService service = new DictionaryService();
       
        service.applyCsv(TestUtils.csvToList(CSV_DICT_CODES, TestEntityUtils::getDate));
    }
}


public class TestUtils {

    private static final String RESOURCE_PATH = "csv/";

    public static <T> List<T> csvToList(String csvFileName, Function<String[], T> mapper) {
        ClassLoader classLoader = TestUtils.class.getClassLoader();
        File file = getFile(classLoader, RESOURCE_PATH, csvFileName);
        return FileUtils.readFileToString(file, StandardCharsets.UTF_8);
        return csvStringToList(csv, mapper);
    }

    public static File getFile(ClassLoader loader, String dirPath, String filePath) {
        String fullPath = StringUtils.stripEnd(dirPath, SLASH) + SLASH + filePath;
        String file = Objects.requireNonNull(loader.getResource(fullPath), fullPath.concat("  not found!")).getFile();
        return new File(file);
    }
}

As I mentioned, If I start it from IDEA like right mouse click on the test`s folder and Run 'All Test' my test start and finish clearly without any error.

Exception when I run test with commande from terminal mvn clean veryfy -Pit

[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.137 s - in my.project.group.db.JdbcTemplateStoredProcedure

[INFO] Running my.project.group.ContextTest

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.951 s <<< FAILURE! - in my.project.group.ContextTest

[ERROR] my.project.group.ContextTestTime elapsed: 0.951 s  <<< ERROR!

java.io.FileNotFoundException: file:\C:\Users\User\AppData\Local\Temp\surefire1195270631651299000\..%5C..%5C..%5C..%5C..%5C..%5Crepos%5CMyProject%5Ccore%5Ctarget%5Ccore-1.0-SNAPSHOT-tests.jar!\csv\dict\V_DICT_USEDDATE_CODE

S.csv (Syntax error in file name, folder name, or volume label)

        at my.project.group.ContextTest.getContextInitializedUsingDb(ContextTest.java:98)

        at my.project.group.ContextTest.<init>(ContextTest.java:64)

Upvotes: 0

Views: 42

Answers (0)

Related Questions