Submit Search
Upload
GeeCON 2014 - Spring Testing
•
0 likes
•
567 views
Mattias Severson
Follow
Spring Testing presented at GeeCON 2014.
Read less
Read more
Technology
Report
Share
Report
Share
1 of 47
Recommended
Api testing
Api testing
Keshav Kashyap
Automated Testing in Angular Slides
Automated Testing in Angular Slides
Jim Lynch
CrossUI Tutorial - Advanced - CRUD
CrossUI Tutorial - Advanced - CRUD
Jack Lee
Service objects in Rails tests - factory_girl replacement
Service objects in Rails tests - factory_girl replacement
Andrzej Krzywda
Testing and Software Writer a year later
Testing and Software Writer a year later
Simon Bagreev
Why vREST?
Why vREST?
vrest_io
Automate REST API Testing
Automate REST API Testing
TechWell
Sync Workitems between multiple Team Projects #vssatpn
Sync Workitems between multiple Team Projects #vssatpn
Lorenzo Barbieri
Recommended
Api testing
Api testing
Keshav Kashyap
Automated Testing in Angular Slides
Automated Testing in Angular Slides
Jim Lynch
CrossUI Tutorial - Advanced - CRUD
CrossUI Tutorial - Advanced - CRUD
Jack Lee
Service objects in Rails tests - factory_girl replacement
Service objects in Rails tests - factory_girl replacement
Andrzej Krzywda
Testing and Software Writer a year later
Testing and Software Writer a year later
Simon Bagreev
Why vREST?
Why vREST?
vrest_io
Automate REST API Testing
Automate REST API Testing
TechWell
Sync Workitems between multiple Team Projects #vssatpn
Sync Workitems between multiple Team Projects #vssatpn
Lorenzo Barbieri
Accelerating DevOps Collaboration with Sauce Labs and JIRA
Accelerating DevOps Collaboration with Sauce Labs and JIRA
Sauce Labs
Client side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karma
Adam Klein
How to tdd your mvp
How to tdd your mvp
The Software House
Modern Tools for API Testing, Debugging and Monitoring
Modern Tools for API Testing, Debugging and Monitoring
Neil Mansilla
Api Testing
Api Testing
Vishwanath KC
Test api
Test api
Ivo Manolov
Combining Front-End and Backend Testing with Sauce Labs & BlazeMeter
Combining Front-End and Backend Testing with Sauce Labs & BlazeMeter
Sauce Labs
HTBYOOFIYRHT RubyConf
HTBYOOFIYRHT RubyConf
Sandy Vanderbleek
Web Performance Culture and Tools at Etsy
Web Performance Culture and Tools at Etsy
Mike Brittain
Database DevOps Anti-patterns
Database DevOps Anti-patterns
Alex Yates
Reasons To Automate API Testing Process
Reasons To Automate API Testing Process
QASource
DevOps 101 for data professionals
DevOps 101 for data professionals
Alex Yates
Web API testing : A quick glance
Web API testing : A quick glance
Dhanalaxmi K
Getting CI right for SQL Server
Getting CI right for SQL Server
Alex Yates
Test first
Test first
Ryan Riley
B4USolution_API-Testing
B4USolution_API-Testing
b4usolution .
Api Testing
Api Testing
Vishwanath KC
ConFESS 2013 - Comparing Functional Java Frameworks
ConFESS 2013 - Comparing Functional Java Frameworks
Mattias Severson
jDays 2015 - Getting Familiar with Spring Boot
jDays 2015 - Getting Familiar with Spring Boot
Mattias Severson
SpringOne 2GX 2013 - Spring Testing
SpringOne 2GX 2013 - Spring Testing
Mattias Severson
GeeCON 2014 - Functional Programming without Lambdas
GeeCON 2014 - Functional Programming without Lambdas
Mattias Severson
Software Passion Summit 2012 - Testing of Spring
Software Passion Summit 2012 - Testing of Spring
Mattias Severson
More Related Content
What's hot
Accelerating DevOps Collaboration with Sauce Labs and JIRA
Accelerating DevOps Collaboration with Sauce Labs and JIRA
Sauce Labs
Client side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karma
Adam Klein
How to tdd your mvp
How to tdd your mvp
The Software House
Modern Tools for API Testing, Debugging and Monitoring
Modern Tools for API Testing, Debugging and Monitoring
Neil Mansilla
Api Testing
Api Testing
Vishwanath KC
Test api
Test api
Ivo Manolov
Combining Front-End and Backend Testing with Sauce Labs & BlazeMeter
Combining Front-End and Backend Testing with Sauce Labs & BlazeMeter
Sauce Labs
HTBYOOFIYRHT RubyConf
HTBYOOFIYRHT RubyConf
Sandy Vanderbleek
Web Performance Culture and Tools at Etsy
Web Performance Culture and Tools at Etsy
Mike Brittain
Database DevOps Anti-patterns
Database DevOps Anti-patterns
Alex Yates
Reasons To Automate API Testing Process
Reasons To Automate API Testing Process
QASource
DevOps 101 for data professionals
DevOps 101 for data professionals
Alex Yates
Web API testing : A quick glance
Web API testing : A quick glance
Dhanalaxmi K
Getting CI right for SQL Server
Getting CI right for SQL Server
Alex Yates
Test first
Test first
Ryan Riley
B4USolution_API-Testing
B4USolution_API-Testing
b4usolution .
Api Testing
Api Testing
Vishwanath KC
What's hot
(17)
Accelerating DevOps Collaboration with Sauce Labs and JIRA
Accelerating DevOps Collaboration with Sauce Labs and JIRA
Client side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karma
How to tdd your mvp
How to tdd your mvp
Modern Tools for API Testing, Debugging and Monitoring
Modern Tools for API Testing, Debugging and Monitoring
Api Testing
Api Testing
Test api
Test api
Combining Front-End and Backend Testing with Sauce Labs & BlazeMeter
Combining Front-End and Backend Testing with Sauce Labs & BlazeMeter
HTBYOOFIYRHT RubyConf
HTBYOOFIYRHT RubyConf
Web Performance Culture and Tools at Etsy
Web Performance Culture and Tools at Etsy
Database DevOps Anti-patterns
Database DevOps Anti-patterns
Reasons To Automate API Testing Process
Reasons To Automate API Testing Process
DevOps 101 for data professionals
DevOps 101 for data professionals
Web API testing : A quick glance
Web API testing : A quick glance
Getting CI right for SQL Server
Getting CI right for SQL Server
Test first
Test first
B4USolution_API-Testing
B4USolution_API-Testing
Api Testing
Api Testing
Viewers also liked
ConFESS 2013 - Comparing Functional Java Frameworks
ConFESS 2013 - Comparing Functional Java Frameworks
Mattias Severson
jDays 2015 - Getting Familiar with Spring Boot
jDays 2015 - Getting Familiar with Spring Boot
Mattias Severson
SpringOne 2GX 2013 - Spring Testing
SpringOne 2GX 2013 - Spring Testing
Mattias Severson
GeeCON 2014 - Functional Programming without Lambdas
GeeCON 2014 - Functional Programming without Lambdas
Mattias Severson
Software Passion Summit 2012 - Testing of Spring
Software Passion Summit 2012 - Testing of Spring
Mattias Severson
Spring santosh
Spring santosh
Pavan Kirshna
Spring complete notes natraz
Spring complete notes natraz
Pavan Kirshna
Spring Boot
Spring Boot
Jaran Flaath
Hibernate natraz
Hibernate natraz
Pavan Kirshna
Spring Booted, But... @JCConf 16', Taiwan
Spring Booted, But... @JCConf 16', Taiwan
Pei-Tang Huang
AppSec & Microservices - Velocity 2016
AppSec & Microservices - Velocity 2016
Sam Newman
Spring Boot
Spring Boot
Pei-Tang Huang
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Matt Raible
Microservices vs monolithic
Microservices vs monolithic
Xuân-Lợi Vũ
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
Matt Raible
Spring by rj
Spring by rj
Shree M.L.Kakadiya MCA mahila college, Amreli
Seminar on Project Management by Rj
Seminar on Project Management by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
Principles of microservices velocity
Principles of microservices velocity
Sam Newman
Weblogic application server
Weblogic application server
Anuj Tomar
Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017
Matt Raible
Viewers also liked
(20)
ConFESS 2013 - Comparing Functional Java Frameworks
ConFESS 2013 - Comparing Functional Java Frameworks
jDays 2015 - Getting Familiar with Spring Boot
jDays 2015 - Getting Familiar with Spring Boot
SpringOne 2GX 2013 - Spring Testing
SpringOne 2GX 2013 - Spring Testing
GeeCON 2014 - Functional Programming without Lambdas
GeeCON 2014 - Functional Programming without Lambdas
Software Passion Summit 2012 - Testing of Spring
Software Passion Summit 2012 - Testing of Spring
Spring santosh
Spring santosh
Spring complete notes natraz
Spring complete notes natraz
Spring Boot
Spring Boot
Hibernate natraz
Hibernate natraz
Spring Booted, But... @JCConf 16', Taiwan
Spring Booted, But... @JCConf 16', Taiwan
AppSec & Microservices - Velocity 2016
AppSec & Microservices - Velocity 2016
Spring Boot
Spring Boot
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Microservices vs monolithic
Microservices vs monolithic
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
Spring by rj
Spring by rj
Seminar on Project Management by Rj
Seminar on Project Management by Rj
Principles of microservices velocity
Principles of microservices velocity
Weblogic application server
Weblogic application server
Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017
Similar to GeeCON 2014 - Spring Testing
SMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step Functions
Amazon Web Services
Serverless Apps with AWS Step Functions
Serverless Apps with AWS Step Functions
Amanda Mackay (she/her)
Continuous Delivery: How RightScale Releases Weekly
Continuous Delivery: How RightScale Releases Weekly
RightScale
Netserv Software Testing
Netserv Software Testing
sthicks14
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2
Sam Brannen
WordPress Acceptance Testing, Solved!
WordPress Acceptance Testing, Solved!
Taylor Lovett
Testing for fun in production Into The Box 2018
Testing for fun in production Into The Box 2018
Ortus Solutions, Corp
Visual Studio 2010 for testers
Visual Studio 2010 for testers
Arpit Dubey
WinAppDriver - Windows Store Apps Test Automation
WinAppDriver - Windows Store Apps Test Automation
Jeremy Kao
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling
Thorsten Kamann
Rapid prototyping of eclipse rcp applications - Eclipsecon Europe 2017
Rapid prototyping of eclipse rcp applications - Eclipsecon Europe 2017
Patrik Suzzi
Getting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe Testing
Mark Rickerby
The what, why and how of web analytics testing
The what, why and how of web analytics testing
Anand Bagmar
QASymphony Atlanta Customer User Group Fall 2017
QASymphony Atlanta Customer User Group Fall 2017
QASymphony
Spring 3 - An Introduction
Spring 3 - An Introduction
Thorsten Kamann
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Delivery
masoodjan
1,2,3 … Testing : Is this thing on(line)? with Mike Martin
1,2,3 … Testing : Is this thing on(line)? with Mike Martin
NETUserGroupBern
About QTP 9.2
About QTP 9.2
chandrasekhar
About Qtp_1 92
About Qtp_1 92
techgajanan
About Qtp 92
About Qtp 92
techgajanan
Similar to GeeCON 2014 - Spring Testing
(20)
SMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step Functions
Serverless Apps with AWS Step Functions
Serverless Apps with AWS Step Functions
Continuous Delivery: How RightScale Releases Weekly
Continuous Delivery: How RightScale Releases Weekly
Netserv Software Testing
Netserv Software Testing
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2
WordPress Acceptance Testing, Solved!
WordPress Acceptance Testing, Solved!
Testing for fun in production Into The Box 2018
Testing for fun in production Into The Box 2018
Visual Studio 2010 for testers
Visual Studio 2010 for testers
WinAppDriver - Windows Store Apps Test Automation
WinAppDriver - Windows Store Apps Test Automation
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling
Rapid prototyping of eclipse rcp applications - Eclipsecon Europe 2017
Rapid prototyping of eclipse rcp applications - Eclipsecon Europe 2017
Getting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe Testing
The what, why and how of web analytics testing
The what, why and how of web analytics testing
QASymphony Atlanta Customer User Group Fall 2017
QASymphony Atlanta Customer User Group Fall 2017
Spring 3 - An Introduction
Spring 3 - An Introduction
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Delivery
1,2,3 … Testing : Is this thing on(line)? with Mike Martin
1,2,3 … Testing : Is this thing on(line)? with Mike Martin
About QTP 9.2
About QTP 9.2
About Qtp_1 92
About Qtp_1 92
About Qtp 92
About Qtp 92
Recently uploaded
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Sinan KOZAK
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
Ridwan Fadjar
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Safe Software
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
Delhi Call girls
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
XfilesPro
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
naman860154
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
hans926745
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Radu Cotescu
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
BookNet Canada
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions
Key Features Of Token Development (1).pptx
Key Features Of Token Development (1).pptx
LBM Solutions
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Delhi Call girls
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
2toLead Limited
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
soniya singh
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Delhi Call girls
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
ThousandEyes
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Alan Dix
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Rafal Los
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
Puma Security, LLC
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Michael W. Hawkins
Recently uploaded
(20)
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
Key Features Of Token Development (1).pptx
Key Features Of Token Development (1).pptx
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
GeeCON 2014 - Spring Testing
1.
Spring Testing Mattias Severson
2.
Mattias @mattiasseverson ! https://github.com/matsev/spring-testing
3.
Agenda • Basic Spring
Testing • Embedded Database • Transactions • Profiles • Controller Tests • Spring Boot
4.
Bank App
5.
Architecture AccountService BankController ImmutableAccount AccountEntityAccountRepository
6.
Basics
7.
! ! public class AccountServiceTest
{ ! @Autowired AccountService aService; ! @Test public void testDoSomething() { aService.doSomething(); // verify ... } } @Autowired
8.
@ContextConfiguration ! @ContextConfiguration("classes=AppConfig.class") public class AccountServiceTest
{ ! @Autowired AccountService aService; ! @Test public void testDoSomething() { aService.doSomething(); // verify ... } } ! ! public class AccountServiceTest { ! @Autowired AccountService aService; ! @Test public void testDoSomething() { aService.doSomething(); // verify ... } }
9.
SpringJUnit4ClassRunner @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(“classes=TestConfig.class") public class AccountServiceTest
{ ! @Autowired AccountService aService; ! @Test public void testDoSomething() { aService.doSomething(); // verify ... } } ! @ContextConfiguration("classes=TestConfig.class public class AccountServiceTest { ! @Autowired AccountService aService; ! @Test public void testDoSomething() { aService.doSomething(); // verify ... } }
10.
Embedded DB AccountRepository AccountEntity
11.
Java Config @Configuration public class
EmbeddedDbConfig { ! @Bean(destroyMethod = "shutdown") public EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder() .setType(EmbeddedDatabaseType.HSQL) .addScript(“classpath:db-schema.sql”) .addScript(“classpath:db-test-data.sql”) .build(); } }
12.
XML Config <jdbc:embedded-database id="dataSource"
type="HSQL"> <jdbc:script location="classpath:db-schema.sql"/> <jdbc:script location="classpath:db-test-data.sql"/> </jdbc:embedded-database>
13.
Demo
14.
Transactions
15.
Tx Test ! @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/application-context.xml") public class
AccountServiceTest { ! @Test public void testDoSomething() { // call DB } ! } @Transactional ! ! ! ! @Test public void testDoSomething() { // call DB } !
16.
Avoid False Positives Always
flush() before validation! ! • Hibernate! - sessionFactory.getCurrentSession().flush();! ! • JPA! - entityManager.flush();
17.
Demo
18.
No Transactions? @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("...") public class
AccountRepositoryTest { ! @Autowired AccountRepository accountRepo; ! @Before public void setUp() { accountRepo.deleteAll(); accountRepo.save(testData); } }
19.
Spring Profiles
20.
Java Config Profile ! @Configuration public
class EmbeddedDbConfig { ! @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder(). // ... } } @Profile(“testProfile”)
21.
Component Profile ! @Component public class
SomeClass implements SomeInterface { ! } @Profile(“testProfile”)
22.
XML Profiles <beans ...> ! ! <bean
id="dataSource"> <!-- Test data source --> </bean> ! ! ! <bean id="dataSource"> <!-- Production data source --> </bean> ! ! </beans> ! ! <beans profile="testProfile"> ! ! ! </beans> ! <beans profile="prodProfile"> ! ! ! </beans> !
23.
Tests and Profiles ! @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(“/application-context.xml”) public
class SomeTest { ! @Autowired SomeClass someClass; ! @Test public void testSomething() { ... } } @ActiveProfiles("testProfile")
24.
Demo AccountRepository AccountEntity AccountService ImmutableAccount
25.
web.xml <web-app ...> ! ! ! ! ! <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> ! </web-app> ! ! <context-param> <param-name>spring.profiles.active</param-name> <param-value>someProfile</param-value> </context-param>
26.
ApplicationContext AnnotationConfigApplicationContext ctx = new
AnnotationConfigApplicationContext(); ctx.getEnvironment().setActiveProfiles("someProfile"); ctx.register(SomeConfig.class); ctx.scan("com.jayway.demo"); ctx.refresh();
27.
Env Property System.getProperty(“spring.profiles.active”); mvn -Dspring.profiles.active=testProfile
28.
Default Profiles ctx.getEnvironment().setDefaultProfiles("..."); System.getProperty("spring.profiles.default"); <context-param> <param-name>spring.profiles.default</param-name> <param-value>defaultProfile</param-value> </context-param> <beans profile="default"> <!--
default beans --> </beans> @Profile("default")
29.
Profile Alternatives • .properties •
Maven Profile
30.
Test Controller AccountRepository AccountService AccountEntity ImmutableAccount BankController
31.
Spring MVC Test
Framework • Call Controllers through DispatcherServlet • MockHttpServletRequest • MockHttpServletResponse
32.
MockMvc MockMvc mockMvc =
MockMvcBuilders .standaloneSetup(new BankController()) .build(); MockMvc mockMvc = MockMvcBuilders .standaloneSetup(new BankController()) .setMessageConverters(...) .setValidator(...) .setConversionService(...) .addInterceptors(...) .setViewResolvers(...) .setLocaleResolver(...) .addFilter(...) .build();
33.
MockMvc MockMvc mockMvc =
MockMvcBuilders .build(); MockMvc mockMvc = MockMvcBuilders .standaloneSetup(new BankController()) .setMessageConverters(...) .setValidator(...) .setConversionService(...) .addInterceptors(...) .setViewResolvers(...) .setLocaleResolver(...) .addFilter(...) .build();
34.
Assertions mockMvc.perform(get("/url") .accept(MediaType.APPLICATION_XML)) .andExpect(response().status().isOk()) .andExpect(content().contentType(“MediaType.APPLICATION_XML”)) .andExpect(xpath(“key”).string(“value”)) .andExpect(redirectedUrl(“url”)) .andExpect(model().attribute(“name”, value));
35.
@WebAppConfiguration @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/application-context.xml") @WebAppConfiguration public class WebApplicationTest
{ ! @Autowired WebApplicationContext wac; !
36.
@WebAppConfiguration @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/application-context.xml") @WebAppConfiguration public class WebApplicationTest
{ ! @Autowired WebApplicationContext wac; ! @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/application-context.xml") @WebAppConfiguration public class WebApplicationTest { ! @Autowired WebApplicationContext wac; ! MockMvc mockMvc; ! @Before public void setUp() { MockMvcBuilders. .webAppContextSetup(wac) .build(); }
37.
Demo
38.
Testing Views • Supported
templates - JSON! - XML! - Velocity! - Thymeleaf! • Except JSP
39.
Spring Boot
40.
test Spring Boot Integration
Test appCtx DB dataSrctxMngr Embedded App Server HTTP
41.
Spring Boot Integration
Tests @SpringApplicationConfiguration @IntegrationTest
42.
Test RESTful API •
RestTemplate • Selenium • HttpClient • ...
43.
REST Assured @Test public void
shouldGetSingleAccount() { expect(). statusCode(HttpStatus.SC_OK). contentType(ContentType.JSON). body("accountNumber", is(1)). body("balance", is(100)). when(). get("/account/1"); }
44.
Demo
45.
Conclusions • Basic Spring
Testing! • Embedded Database! • Transactions! • Profiles! • Controller Tests! • Spring Boot
46.
Questions?
47.
@mattiasseverson ! https://github.com/matsev/spring-testing