Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Testing Spring Boot Applications
Search
Andy Wilkinson
October 09, 2019
Programming
150
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
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
330
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
480
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
370
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
150
R8 の設定見直しでアプリサイズ削減
andpad
0
210
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.1k
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
外から家のPCの電源入れたい!をPHPで解決する
kawashimo0
1
130
カツオ、ご期待ください
suneo3476
0
180
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
130
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
110
Featured
See All Featured
Become a Pro
speakerdeck
PRO
31
6.3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
530
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
220
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
300
Rails Girls Zürich Keynote
gr2m
96
14k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
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