title: Junit 5 with Spring Boot: When to use @ExtendWith Spring or Mockito?
body: <p>I Have the following <strong>abstract unit test class</strong> that all my concrete unit test classes extend:</p>
  
  <pre><code>@ExtendWith(SpringExtension.class)
  //@ExtendWith(MockitoExtension.class)
  @SpringBootTest(
      classes = PokerApplication.class,
      webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
  )
  public abstract class AbstractUnitTests {
  
      @MockBean
      public RoundService roundService;
  
      @MockBean
      public RoundRepository roundRepository;
  }
  </code></pre>
  
  <p>What is the difference between using <code>@ExtendWith(SpringExtension.class)</code> or <code>@ExtendWith(MockitoExtension.class)</code>?</p>
  
  <p>I ask as using either of the annotations seems to make no difference and both work respectively in my code - allowing me to use Junit5. So why do both work?</p>
  
  <p><strong>Concrete test class:</strong></p>
  
  <pre><code>    @DisplayName("Test RoundService")
      public class RoundsServiceTest extends AbstractUnitTests {
  
          private static String STUB_USER_ID = "user3";
  
          // class under test
          @InjectMocks
          RoundService roundService;
  
          private Round round;
  
          private ObjectId objectId;
  
          @BeforeEach //note this replaces the junit 4 @Before
          public void setUp() {
  
              initMocks(this);
              round = Mocks.round();
              objectId = Mocks.objectId();
          }
  
          @DisplayName("Test RoundService.getAllRoundsByUserId()")
          @Test
          public void shouldGetRoundsByUserId() {
  
              // setup
              given(roundRepository.findByUserId(anyString())).willReturn(Collections.singletonList(round));
  
              // call method under test
              List&lt;Round&gt; rounds = roundService.getRoundsByUserId(STUB_USER_ID);
  
              // asserts
              assertNotNull(rounds);
              assertEquals(1, rounds.size());
              assertEquals("user3", rounds.get(0).userId());
          }
  }
  </code></pre>
  
  <p><strong>Relevant Build.gradle section</strong> :</p>
  
  <pre><code>dependencies {
      implementation 'org.springframework.boot:spring-boot-starter'
      implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
      compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.2.2.RELEASE'
  
      compileOnly 'org.projectlombok:lombok'
      annotationProcessor 'org.projectlombok:lombok'
  
      testImplementation('org.springframework.boot:spring-boot-starter-test') {
          exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
      }
      implementation 'junit:junit:4.12'
  }
  
  test {
      useJUnitPlatform()
  }
  </code></pre>