jeudi 30 mai 2019

AssertJ: make assertion that all Assert objects were asserted upon

When using the AssertJ library, I'm interested in being able to assert that all org.assertj.core.api.Assert objects had an actual assertion made on them. That is, a test such as the following should fail because it is clearly a mistake:

import static org.assertj.core.api.Assertions.assertThat;

// ... elided ...

@Test
public void unfinishedAssertion() {
    assertThat("str");
}

Is there a way to configure this with AssertJ, or to make this assertion in a JUnit @After method?

My only thought is to provide a static factory like assertThat that returns a proxy, delegating all method invocations to the underlying Assert, and using an After method to assert that the proxy had at least one invocation with a method that was not Assert#as or Assert#withFailMessage, etc., but this seems cumbersome and unnecessary as the library should provide this functionality itself.

Aucun commentaire:

Enregistrer un commentaire