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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Andy Wilkinson
October 09, 2019
Programming
140
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
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
790
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
430
Build-to-own AI: Agentic Development for Humans
inesmontani
PRO
0
130
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
430
継続モナドとリアクティブプログラミング
yukikurage
3
660
メールのエイリアス機能を履き違えない
isshinfunada
0
150
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
120
What's New in Android 2026
veronikapj
0
240
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
570
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
2
1.3k
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
140
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
900
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Color Theory Basics | Prateek | Gurzu
gurzu
0
400
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
230
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
780
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
450
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
300
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
540
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.1k
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