Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Testing Spring Boot Applications
Search
Andy Wilkinson
October 09, 2019
Programming
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Testing Spring Boot Applications
Andy Wilkinson
October 09, 2019
More Decks by Andy Wilkinson
See All by Andy Wilkinson
Mastering Spring Boot's Actuator | Spring IO 2018
ankinson
4
1.5k
Documenting RESTful APIs
ankinson
4
1.2k
Documenting RESTful APIs – Webinar
ankinson
9
9.6k
Documenting RESTful APIs – Spring Exchange 2014
ankinson
4
1.3k
Other Decks in Programming
See All in Programming
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.2k
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
180
はてなアカウント基盤 State of the Union
cockscomb
1
1.2k
Performance Engineering for Everyone
elenatanasoiu
0
250
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
780
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
4
520
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
250
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.9k
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
140
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
270
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
320
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
190
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
240
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
250
The Limits of Empathy - UXLibs8
cassininazir
1
380
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
310
Crafting Experiences
bethany
1
200
Leo the Paperboy
mayatellez
7
1.9k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Designing Experiences People Love
moore
143
24k
Mobile First: as difficult as doing things right
swwweet
225
10k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.1k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
180
The SEO Collaboration Effect
kristinabergwall1
1
500
Transcript
Testing Spring Boot Applications Andy Wilkinson @ankinson
@ankinson Why Bother Testing At All?
@ankinson
@ankinson Risk None YOLO Tests 0 Lots
@ankinson
@ankinson Unit Tests
@ankinson
@ankinson MockRestServiceServer OkHTTP’s MockWebServer Spring Data Repositories JdbcTemplate
@ankinson Testcontainers
@ankinson https://www.testcontainers.org
@ankinson @SpringBootTest @Testcontainers(disabledWithoutDocker = true) @ContextConfiguration(initializers = ExampleIntegrationTests.Initializer.class) class ExampleIntegrationTests
{ @Container public static CassandraContainer<?> cassandra = new CassandraContainer<>(); static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { @Override public void initialize(ConfigurableApplicationContext context) { int cqlPort = cassandra.getMappedPort(CassandraContainer.CQL_PORT); TestPropertyValues.of("spring.data.cassandra.port=" + cqlPort) .applyTo(context.getEnvironment()); } } }
@ankinson Integration Tests
@ankinson @SpringBootTest
@ankinson Context Caching
@ankinson @SpringBootTest(properties="spring.jmx.enabled=true") @ActiveProfiles("standalone") @TestPropertySource(locations="standalone.properties") class ExampleIntegrationTests { @Test void contextLoads()
{ } } @ContextConfiguration @Import @TestPropertySource @ActiveProfiles @SpringBootTest
@ankinson @DirtiesContext
@ankinson Sliced Tests
@ankinson @JsonTest @WebMvcTest @WebFluxTest @DataJpaTest @JdbcTest @JooqTest @DataMongoTest @DataNeo4jTest @DataRedisTest
@DataLdapTest @RestClientTest
@ankinson @WebMvcTest @DataJpaTest OrderRepository extends JpaRepository<…> @Controller OrderController @Controller CustomerController
CustomerRepository extends JpaRepository<…> @SpringBootApplication Application
@ankinson @MockBean and @SpyBean
@ankinson @WebMvcTest class CustomerControllerIntegrationTests { @Autowired private MockMvc mockMvc; @Configuration
static class RepositoryConfiguration { @Bean CustomerRepository customers() { return mock(CustomerRepository.class); } @Bean OrderRepository orders() { return mock(OrderRepository.class); } } }
@ankinson Customer Customer Order @WebMvcTest class CustomerControllerTests { @Autowired private
MockMvc mockMvc; @MockBean private CustomerRepository customers; @MockBean private OrderRepository orders; } (controllers = CustomerController.class)
JUnit 5: Evolution and Innovation Sam Brannen Thursday 10:30am–11:40am Ballroom
F
Thanks! Q&A Andy Wilkinson @ankinson #springone @s1p