title: Is it OK to use SpringRunner in unit tests?
body: <p>We are arguing about this approach with my colleagues. They say to use SpringRunner only on integration or functional levels.</p>
  
  <p>The question is what pros and cons of using it in level below? </p>
  
  <p>For example I have simple bean:</p>
  
  <pre><code>public class RewardDurationCalculator {
  
      private Clock clock;
  
      public OptionalLong calculate(DurationType durationType, List&lt;Pass&gt; passes) {
          long now = Instant.now(clock).getEpochSecond();
          switch (durationType) {
              case FULL_PASS:
                  return getCurrentPassDuration(passes, now);
              case TILL_THE_END_OF_THE_CURRENT_ACTIVE_PASS:
                  return getTimeInCurrentPassLeft(passes, now);
          }
          return OptionalLong.empty();
      }
  
      private OptionalLong getCurrentPassDuration(List&lt;Pass&gt; passes, long now) {
          return passes.stream()
                  .filter(currentPass(now))
                  .mapToLong(Pass::getDuration)
                  .findFirst();
      }
  
      private OptionalLong getTimeInCurrentPassLeft(List&lt;Pass&gt; passes, long now) {
          return passes.stream()
                  .filter(currentPass(now))
                  .mapToLong(pass -&gt; getEndTs(pass) - now)
                  .findFirst();
      }
  
      private Predicate&lt;Pass&gt; currentPass(long now) {
          return pass -&gt; pass.getStartTs() &gt;= now &amp;&amp; now &lt;= getEndTs(pass);
      }
  
      private long getEndTs(Pass pass) {
          return pass.getStartTs() + pass.getDuration();
      }
  
  }
  </code></pre>
  
  <p>that is doing some calculation logic. For it I have also spring config:</p>
  
  <pre><code>@Configuration
  public class RewardDurationCalculatorConfiguration {
  
      @Bean
      public RewardDurationCalculator rewardDurationCalculator(Clock clock) {
          return new RewardDurationCalculator(clock);
      }
  
  }
  </code></pre>
  
  <p>So why can't I write unit test for it like this:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @ContextConfiguration(classes = RewardDurationCalculatorConfiguration.class)
  public class RewardDurationCalculatorTest {
  
      @MockBean
      private Clock clock;
      @Autowired
      private RewardDurationCalculator rewardDurationCalculator;
  
      @Test
      public void testCalculateCurrentPassDurationShouldBeReturnedIfPassWasCreatedRightNow() {
          rewardDurationCalculator.calculate(DurationType.FULL_PASS, Collections.emptyList());
      }
  
  }
  </code></pre>
  
  <p>What cons I can face with using such approach?</p>