Spring Boot Testing Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 50: Line 50:


<syntaxhighlight lang='java'>
<syntaxhighlight lang='java'>
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest
public class MyTests {
public class MyTests {
Line 61: Line 60:
}
}
</syntaxhighlight>
</syntaxhighlight>
For an example of how to use Mockito mocks, see: {{Internal|Spring_Boot_Mockito_Support#Overview|Spring Boot Mockito Support}}


=Testing Logging Configuration=
=Testing Logging Configuration=


By default, test logging is executed by [[Logback]].
By default, test logging is executed by [[Logback]].

Revision as of 02:42, 3 October 2021

External

Internal

Overview

Dependencies

Use:

dependencies {
    testImplementation('org.springframework.boot:spring-boot-starter-test')
}

This started dependency pulls everything that is needed to write JUnit tests.

Annotations

Spring Boot Mockito Support

Spring Boot Mockito Support

The Default XyzApplicationTests

Spring Initializr creates a

@SpringBootTest
class XyzApplicationTests {
  @Test
  void contextLoads() {
  }
}

How does this work? How is this useful? Does it use name conventions?

SpringBoot Test Example

@SpringBootTest
public class MyTests {

    @Autowired
    private SomeComponent someComponentWeWantToTest;

    // ...

}

For an example of how to use Mockito mocks, see:

Spring Boot Mockito Support

Testing Logging Configuration

By default, test logging is executed by Logback.