Skip to content

ParameterizedTest does not work accurately #12

@felix-seifert

Description

@felix-seifert

I want to assert that the exit code will be 1 for several input files. If I test this by writing several tests, the test reports display truthfully what happens if I start the program with these input file conventionally. As the tests have the same structure, I combined them in a @ParameterizedTest with different file names as the parameter. This parameterized test, however, seems to report a test success for every iteration if at least one iteration is successful which does not give me the correct test result.

When I run the two tests separately, one test fails and one test succeeds.

  @Test
  @ExpectSystemExitWithStatus(1)
  void parseErrorTest_fail() throws IOException {
    final String pathToError = pathPrefix + "error/comments-error-1.cpp";
    CompilerMain.main(new String[]{pathToError});
  }

  @Test
  @ExpectSystemExitWithStatus(1)
  void parseErrorTest_succeed() throws IOException {
    final String pathToError = pathPrefix + "error/parse-error.cpp";
    CompilerMain.main(new String[]{pathToError});
  }

If I combine these two tests in a @ParameterizedTest, each iteration seems to be succeeding.

  @ParameterizedTest
  @ValueSource(strings = {"parse-error.cpp", "comments-error-1.cpp"})
  @ExpectSystemExitWithStatus(1)
  void parseErrorTest(final String fileName) throws IOException {
    final String pathToError = pathPrefix + "error/" + fileName;
    CompilerMain.main(new String[]{pathToError});
  }

I am using JUnit version 5.8.1 for junit-jupiter-api and junit-jupiter-params. The version of junit5-system-exit is 1.1.1. I am running on Java 17 (OpenJDK Runtime Environment GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05)).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions