Skip to content

[Proposition] Adopt JUnit 5 & AssertJ #139

Open
@echebbi

Description

@echebbi

Proposal

Tests are currently written with JUnit 4 and I believe we should move to JUnit 5:

  • JUnit 5 makes easier to parameterize a test
  • JUnit 5 makes easier to organize tests (e.g. through @Nested and @DisplayName):

image

I believe this is important because some test classes are becoming heavy (BuildTest is 1k lines, EvalTest is 1.3k and TypeValidatorTest 1.6k) which makes harder and harder to browse existing tests and can lead to duplicated tests.

Moreover, I suggest adopting AssertJ which fluent API makes tests much more readable:

@Test @DisplayName("executes all its tasks")
void executes_all_its_tasks() {
    split.run(context);
    assertThat(split.branches()).allMatch(Activity::hasRun);
}

AssertJ also provides SoftAssertions, a way to test several predicates at once. We currently have a lot of tests that stop early in case of failure and do not check all their predicates which hence could benefit from this API, e.g.:

assertEquals(msg.toString(), 6, msg.size());
assertMsgEquals(ValidationMessageLevel.ERROR, 241, 260, "[Set(java.lang.Integer)] cannot be removed from [Sequence(ecore::EBoolean)] (expected [Sequence(ecore::EBoolean),ecore::EBoolean])\n--------------------------------------------------\nMake sure both collections hold the same type", msg.get(0));
assertMsgEquals(ValidationMessageLevel.ERROR, 283, 305, "[Sequence(java.lang.String)] cannot be removed from [Set(ecore::EClass)] (expected [Set(ecore::EClass),ecore::EClass])\n--------------------------------------------------\nMake sure both collections hold the same type", msg.get(1));
assertMsgEquals(ValidationMessageLevel.ERROR, 414, 433, "[Set(java.lang.Integer)] cannot be removed from [Sequence(ecore::EBoolean)] (expected [Sequence(ecore::EBoolean),ecore::EBoolean])\n--------------------------------------------------\nMake sure both collections hold the same type", msg.get(2));
assertMsgEquals(ValidationMessageLevel.ERROR, 452, 474, "[Sequence(java.lang.String)] cannot be removed from [Set(ecore::EClass)] (expected [Set(ecore::EClass),ecore::EClass])\n--------------------------------------------------\nMake sure both collections hold the same type", msg.get(3));
assertMsgEquals(ValidationMessageLevel.ERROR, 500, 519, "[Set(java.lang.Integer)] cannot be removed from [Sequence(ecore::EString)] (expected [Sequence(ecore::EString),ecore::EString])\n--------------------------------------------------\nMake sure both collections hold the same type", msg.get(4));
assertMsgEquals(ValidationMessageLevel.ERROR, 539, 566, "[Sequence(java.lang.Boolean)] cannot be removed from [Sequence(ecore::EInt)] (expected [Sequence(ecore::EInt),ecore::EInt])\n--------------------------------------------------\nMake sure both collections hold the same type", msg.get(5));

To be done

  • Add JUnit 5 & AssertJ to the target platform (warning: they are in Orbit, which may slow down first Maven build)
  • Make current tests use JUnit 5 and AssertJ

Discussion

@dvojtise do you see any reason to stick to JUnit 4?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions