SlideShare a Scribd company logo
1 of 63
Download to read offline
Testing with Spring:
An Introduction
Sam Brannen
@sam_brannen
Spring eXchange | London, England | November 6, 2014
eXchange 2014
2
Sam Brannen
•  Spring and Java Consultant @ Swiftmind
•  Java Developer for over 15 years
•  Spring Framework Core Committer since 2007
–  Component lead for spring-test
•  Spring Trainer
•  Speaker on Spring, Java, and testing
•  Swiss Spring User Group Lead
3
Swiftmind
Experts in Spring and Enterprise Java
Areas of expertise
•  Spring *
•  Java EE
•  Software Architecture
•  Software Engineering Best Practices
Where you find us
•  Zurich, Switzerland
•  @swiftmind
•  http://www.swiftmind.com
4
A Show of Hands…
? ?
?
?
5
Agenda
•  Unit testing
•  Integration testing
•  Context management and DI
•  Transactions and SQL scripts
•  Spring MVC and REST
•  Q&A
6
Unit Testing
7
Unit Tests
•  are simple to set up
•  use dynamic mocks or stubs for dependencies
•  instantiate the SUT, execute the code, and assert
expectations
•  run fast
•  but only test a single unit
8
Spring and Unit Testing
•  POJO-based programming model
–  Program to interfaces
–  IoC / Dependency Injection
–  Out-of-container testability
–  Third-party mocking frameworks (Mockito, …)
•  Spring testing mocks/stubs
–  Servlet
–  Portlet
–  JNDI
–  Spring Environment
9
EventService API
public interface EventService {
List<Event> findAll();
Event save(Event event);
void delete(Event event);
}
10
EventService Implementation (1/2)
@Service
@Transactional
public class StandardEventService implements EventService {
private final EventRepository repository;
@Autowired
public StandardEventService(EventRepository repository) {
this.repository = repository;
}
// ...
11
EventService Implementation (2/2)
public Event save(final Event event) {
// additional business logic ...
return repository.save(event);
}
12
EventService Unit Test (1/2)
public class StandardEventServiceTests {
private StandardEventService service;
private EventRepository repository;
@Before
public void setUp() {
repository = mock(EventRepository.class);
service = new StandardEventService(repository);
}
13
EventService Unit Test (2/2)
@Test
public void save() {
Event event = new Event();
event.setName("test event");
event.setDescription("testing");
given(repository.save(any(Event.class)))
.willReturn(event);
Event savedEvent = service.save(event);
assertThat(savedEvent, is(equalTo(event)));
}
14
Integration Testing
15
Integration Tests
•  test interactions between multiple components
•  relatively easy to set up…
•  without external system dependencies
•  challenging to set up…
•  with external system dependencies
•  more challenging…
•  if application code depends on the container
16
Integration Test Complexity
Complexity
Dependency
no external systems
external systems
container
17
Modern Enterprise Java Apps
•  Integrate with external systems
•  SMTP, FTP, LDAP, RDBMS, Web Services, JMS
•  Rely on container-provided functionality
•  data sources, connection factories, transaction
managers
18
Effective Integration Testing
•  Fast
•  Repeatable
•  Automated
•  Easy to configure
•  Run out-of-container
19
Out-of-container
•  Zero reliance on availability of external systems
•  Can be run anywhere
•  developer workstation
•  CI server
•  Approximate the production environment
•  Embedded database
•  In-memory SMTP server, FTP server, JMS broker
20
Spring TestContext Framework
21
In a nutshell…
The Spring TestContext Framework
… provides annotation-driven unit and integration testing
support that is agnostic of the testing framework in use
… with a strong focus on convention over configuration
and reasonable defaults that can be overridden through
annotation-based configuration
… and integrates with JUnit and TestNG out of the box.
22
Testimony
“The Spring TestContext Framework is an
excellent example of good annotation usage
as it allows composition rather than
inheritance.”
- Costin Leau
23
Feature Set
•  Context management and caching
•  Dependency Injection of test fixtures
•  Transaction management
•  SQL script execution
•  Spring MVC and REST
•  Extension points for customization
24
Spring 2.5 Testing Themes
•  @ContextConfiguration
–  XML config files
–  Context caching
•  @TestExecutionListeners
–  Dependency injection: @Autowired, etc.
–  @DirtiesContext
–  @Transactional, @BeforeTransaction, etc.
•  SpringJUnit4ClassRunner
•  Abstract base classes for JUnit and TestNG
25
Spring 3.x Testing Themes (1/2)
•  Embedded databases
–  <jdbc:embedded-database /> &
<jdbc:initialize-database />
–  EmbeddedDatabaseBuilder &
EmbeddedDatabaseFactoryBean
•  @Configuration classes
•  @ActiveProfiles
•  ApplicationContextInitializers
26
Spring 3.x Testing Themes (2/2)
•  @WebAppConfiguration
–  Loading WebApplicationContexts
–  Testing request- and session-scoped beans
•  @ContextHierarchy
–  Web, Batch, etc.
•  Spring MVC Test framework
–  Server-side MVC and REST tests
–  Client-side REST tests
27
Spring 4.0 Testing Themes
•  SocketUtils
–  Scan for available UDP & TCP ports
•  ActiveProfilesResolver API
–  Programmatic alternative to static profile strings
–  Set via resolver attribute in @ActiveProfiles
•  Meta-annotation support for tests
–  Attribute overrides (optional and required)
28
New in 4.1 – Context Config
•  Context config with Groovy scripts
•  Declarative configuration for test property sources
–  @TestPropertySource
29
New in 4.1 – Transactions & SQL
•  Programmatic test transaction management
–  TestTransaction API
•  Declarative SQL script execution
–  @Sql, @SqlConfig, @SqlGroup
•  Improved docs for transactional tests
30
New in 4.1 – TestExecutionListeners
•  Automatic discovery of default TestExecutionListeners
–  Uses SpringFactoriesLoader
–  Already used by Spring Security
•  Merging custom TestExecutionListeners with defaults
–  @TestExecutionListeners(mergeMode=
MERGE_WITH_DEFAULTS)
–  Defaults to REPLACE_DEFAULTS
31
New in 4.1 – Spring MVC Test
•  Assert JSON responses with JSON Assert
–  Complements JSONPath support
•  Create MockMvcBuilder recipes with MockMvcConfigurer
–  Developed to apply Spring Security setup but can be used
by anyone
•  AsyncRestTemplate support in MockRestServiceServer
–  For asynchronous client-side testing
32
Context Management
33
@ContextConfiguration
•  Declared on test class
–  Inheritance supported but overridable
–  Spring Boot: use @SpringApplicationConfiguration
•  ContextLoader loads ApplicationContext based on:
–  Configuration in annotation
–  Or by detecting default configuration
•  Supports:
–  XML configuration files
–  @Configuration classes
–  Groovy scripts
34
@WebAppConfiguration
•  Declared on test class
•  Instructs Spring to load a WebApplicationContext for the test
•  ServletTestExecutionListener ensures that Servlet API mocks
are properly configured
•  Most often used with the Spring MVC Test Framework
35
@ContextHierarchy
•  Declared on test class
–  Used with @ContextConfiguration
•  Configures hierarchies of test application contexts
–  Useful for Spring MVC, Spring Batch, etc.
36
@ActiveProfiles
•  Declared on test class
–  Used with @ContextConfiguration
•  Configures which bean definition profiles should be active
when the test’s ApplicationContext is loaded
•  Active profiles can be configured:
–  Declaratively within the annotation
–  Or programmatically via a custom ActiveProfilesResolver
37
Context Caching
•  The Spring TestContext Framework caches all application
contexts within the same JVM process!
•  Cache key is generated based on configuration in:
–  @ContextConfiguration
–  @ContextHierarchy
–  @WebAppConfiguration
–  @ActiveProfiles
•  Use @DirtiesContext to remove a given test from the cache
38
Ex: Context Configuration
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextHierarchy({
@ContextConfiguration(classes = RootConfig.class),
@ContextConfiguration(classes = WebConfig.class)
})
@ActiveProfiles("dev")
public class ControllerIntegrationTests {
// ...
39
Dependency Injection
40
DI within Integration Tests
•  Dependencies can be injected into a test instance from
the test’s ApplicationContext
•  Using @Autowired, @Inject, @PersistenceContext, etc.
•  The ApplicationContext itself can also be injected into test
instances…
•  @Autowired ApplicationContext
•  @Autowired WebApplicationContext
41
EventService Integration Test
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class EventServiceIntegrationTests {
@Autowired EventService service;
@Test
public void save() {
Event event = new Event("test event");
Event savedEvent = service.save(event);
assertNotNull(savedEvent.getId());
// ...
}
42
Transactional Tests
43
Transactions in Spring
•  Spring-managed transactions: managed by Spring in
the ApplicationContext
–  @Transactional and AOP
•  Application-managed transactions: managed
programmatically within application code
–  TransactionTemplate and
TransactionSynchronizationManager
•  Test-managed transactions: managed by the Spring
TestContext Framework
–  @Transactional on test classes and test methods
–  Transaction is rolled back by default!
44
Ex: Declarative Tx Management in Tests
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@Transactional
public class TransactionalTests {
@Test
public void withinTransaction() {
/* ... */
} What if we want to
stop & start the
transaction within
the test method?
45
TestTransaction API
•  Static methods for interacting with test-managed
transactions
–  isActive()
–  isFlaggedForRollback()
–  flagForCommit()
–  flagForRollback()
–  end()
–  start()
query status
change default rollback setting
end: roll back or commit based on flag
start: new tx with default rollback setting
46
Ex: Programmatic Tx Mgmt in Tests
@Test
public void withinTransaction() {
// assert initial state in test database:
assertNumUsers(2);
deleteFromTables("user");
// changes to the database will be committed
TestTransaction.flagForCommit();
TestTransaction.end();
assertNumUsers(0);
TestTransaction.start();
// perform other actions against the database that will
// be automatically rolled back after test completes...
}
47
SQL Script Execution
48
SQL Script Execution Options
•  At ApplicationContext startup via:
•  <jdbc> XML namespace
•  EmbeddedDatabaseBuilder in Java Config
•  Programmatically during tests with:
•  ScriptUtils, ResourceDatabasePopulator, or abstract
transactional base test classes for JUnit and TestNG
•  Declaratively via @Sql, @SqlConfig, & @SqlGroup
•  Per test method
•  Per test class
49
Ex: Embedded Database in Java Config
EmbeddedDatabase db = new EmbeddedDatabaseBuilder()
.setType(H2)
.setScriptEncoding("UTF-8")
.ignoreFailedDrops(true)
.addScript("schema.sql")
.addScripts("user_data.sql", "country_data.sql")
.build();
// ...
db.shutdown();
50
Ex: Embedded Database in XML Config
<jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="classpath:/schema.sql" />
<jdbc:script location="classpath:/user_data.sql" />
</jdbc:embedded-database>
51
Ex: Populate Database in XML Config
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:/schema_01.sql" />
<jdbc:script location="classpath:/schema_02.sql" />
<jdbc:script location="classpath:/data_01.sql" />
<jdbc:script location="classpath:/data_02.sql" />
</jdbc:initialize-database>
52
Ex: @Sql in Action
@ContextConfiguration
@Sql({ "schema1.sql", "data1.sql" })
public class SqlScriptsTests {
@Test
public void classLevelScripts() { /* ... */ }
@Test
@Sql({ "schema2.sql", "data2.sql" })
public void methodLevelScripts() { /* ... */ }
53
@Sql - Repeatable Annotation (Java 8)
@Test
@Sql(
scripts="/test-schema.sql",
config = @SqlConfig(commentPrefix = "`")
@Sql("/user-data.sql")
public void userTest() {
// code that uses the test schema and test data
}
Schema uses
custom syntax
54
@Sql wrapped in @SqlGroup (Java 6/7)
@Test
@SqlGroup({
@Sql(
scripts="/test-schema.sql",
config = @SqlConfig(commentPrefix = "`"),
@Sql("/user-data.sql")
})
public void userTest() {
// code that uses the test schema and test data
}
55
Spring MVC Test Framework
56
What is Spring MVC Test?
•  Dedicated support for testing Spring MVC applications
•  Fluent API
•  Very easy to write
•  Includes client and server-side support
•  Servlet container not required
57
Details
•  Included in spring-test module of Spring Framework
3.2
•  Builds on
–  TestContext framework for loading Spring MVC
configuration
–  MockHttpServlet[Request|Response] and other
mock types
•  Server-side tests involve DispatcherServlet
•  Client-side REST testing for code using RestTemplate
58
Ex: Web Integration Test (1/2)
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextHierarchy({
@ContextConfiguration(classes = RootConfig.class),
@ContextConfiguration(classes = WebConfig.class)
})
@ActiveProfiles("dev")
public class ControllerIntegrationTests {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
// ...
59
Ex: Web Integration Test (2/2)
@Before
public void setup() {
this.mockMvc = MockMvcBuilders
.webAppContextSetup(this.wac).build();
}
@Test
public void person() throws Exception {
this.mockMvc.perform(get("/person/42")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string("{"name":"Sam"}"));
}
60
In Closing…
61
Spring Resources
•  Spring Framework
–  http://projects.spring.io/spring-framework
•  Spring Guides
–  http://spring.io/guides
•  Spring Forums
–  http://forum.spring.io
•  Spring JIRA
–  https://jira.spring.io
•  Spring on GitHub
–  https://github.com/spring-projects/spring-framework
62
Blogs
•  Swiftmind Blog
–  http://www.swiftmind.com/blog
•  Spring Blog
–  http://spring.io/blog
63
Q & A
Sam Brannen
twitter: @sam_brannen
www.slideshare.net/sbrannen
www.swiftmind.com

More Related Content

What's hot

Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootJosué Neis
 
API Asynchrones en Java 8
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8José Paumard
 
Testing Angular
Testing AngularTesting Angular
Testing AngularLilia Sfaxi
 
Saving Time By Testing With Jest
Saving Time By Testing With JestSaving Time By Testing With Jest
Saving Time By Testing With JestBen McCormick
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepGuo Albert
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambdaManav Prasad
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockitoshaunthomas999
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action Alex Movila
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8LivePerson
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 

What's hot (20)

Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
API Asynchrones en Java 8
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
Saving Time By Testing With Jest
Saving Time By Testing With JestSaving Time By Testing With Jest
Saving Time By Testing With Jest
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Junit
JunitJunit
Junit
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 

Viewers also liked

Testing Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkTesting Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkDmytro Chyzhykov
 
Spring Framework 3.2 - What's New
Spring Framework 3.2 - What's NewSpring Framework 3.2 - What's New
Spring Framework 3.2 - What's NewSam Brannen
 
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Rossen Stoyanchev
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 

Viewers also liked (6)

Testing Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkTesting Web Apps with Spring Framework
Testing Web Apps with Spring Framework
 
Spring Framework 3.2 - What's New
Spring Framework 3.2 - What's NewSpring Framework 3.2 - What's New
Spring Framework 3.2 - What's New
 
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Spring boot
Spring bootSpring boot
Spring boot
 

Similar to Testing with Spring: An Introduction

Testing Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsTesting Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsSam Brannen
 
Testing with Spring 4.x
Testing with Spring 4.xTesting with Spring 4.x
Testing with Spring 4.xSam Brannen
 
Test driven
Test drivenTest driven
Test drivenAnand Iyer
 
Testing Rest with Spring by Kostiantyn Baranov (Senior Software Engineer, Gl...
Testing Rest with Spring  by Kostiantyn Baranov (Senior Software Engineer, Gl...Testing Rest with Spring  by Kostiantyn Baranov (Senior Software Engineer, Gl...
Testing Rest with Spring by Kostiantyn Baranov (Senior Software Engineer, Gl...GlobalLogic Ukraine
 
Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Sam Brannen
 
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenSpring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenJAX London
 
JLove - Replicating production on your laptop using the magic of containers
JLove - Replicating production on your laptop using the magic of containersJLove - Replicating production on your laptop using the magic of containers
JLove - Replicating production on your laptop using the magic of containersGrace Jansen
 
Spring Framework 4.1
Spring Framework 4.1Spring Framework 4.1
Spring Framework 4.1Sam Brannen
 
Effective out-of-container Integration Testing
Effective out-of-container Integration TestingEffective out-of-container Integration Testing
Effective out-of-container Integration TestingSam Brannen
 
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012Sam Brannen
 
API Testing with Open Source Code and Cucumber
API Testing with Open Source Code and CucumberAPI Testing with Open Source Code and Cucumber
API Testing with Open Source Code and CucumberSmartBear
 
SpringOne Tour: An Introduction to Azure Spring Apps Enterprise
SpringOne Tour: An Introduction to Azure Spring Apps EnterpriseSpringOne Tour: An Introduction to Azure Spring Apps Enterprise
SpringOne Tour: An Introduction to Azure Spring Apps EnterpriseVMware Tanzu
 
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.pptNaviAningi
 
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.pptKKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.pptKiran Kumar SD
 
JBCN_Testing_With_Containers
JBCN_Testing_With_ContainersJBCN_Testing_With_Containers
JBCN_Testing_With_ContainersGrace Jansen
 
Ensuring Software Quality Through Test Automation- Naperville Software Develo...
Ensuring Software Quality Through Test Automation- Naperville Software Develo...Ensuring Software Quality Through Test Automation- Naperville Software Develo...
Ensuring Software Quality Through Test Automation- Naperville Software Develo...LinkCompanyAdmin
 
Cypress Testing.pptx
Cypress Testing.pptxCypress Testing.pptx
Cypress Testing.pptxJasmeenShrestha
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsOrtus Solutions, Corp
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...Postman
 
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Sam Brannen
 

Similar to Testing with Spring: An Introduction (20)

Testing Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsTesting Spring MVC and REST Web Applications
Testing Spring MVC and REST Web Applications
 
Testing with Spring 4.x
Testing with Spring 4.xTesting with Spring 4.x
Testing with Spring 4.x
 
Test driven
Test drivenTest driven
Test driven
 
Testing Rest with Spring by Kostiantyn Baranov (Senior Software Engineer, Gl...
Testing Rest with Spring  by Kostiantyn Baranov (Senior Software Engineer, Gl...Testing Rest with Spring  by Kostiantyn Baranov (Senior Software Engineer, Gl...
Testing Rest with Spring by Kostiantyn Baranov (Senior Software Engineer, Gl...
 
Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011
 
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenSpring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
 
JLove - Replicating production on your laptop using the magic of containers
JLove - Replicating production on your laptop using the magic of containersJLove - Replicating production on your laptop using the magic of containers
JLove - Replicating production on your laptop using the magic of containers
 
Spring Framework 4.1
Spring Framework 4.1Spring Framework 4.1
Spring Framework 4.1
 
Effective out-of-container Integration Testing
Effective out-of-container Integration TestingEffective out-of-container Integration Testing
Effective out-of-container Integration Testing
 
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
 
API Testing with Open Source Code and Cucumber
API Testing with Open Source Code and CucumberAPI Testing with Open Source Code and Cucumber
API Testing with Open Source Code and Cucumber
 
SpringOne Tour: An Introduction to Azure Spring Apps Enterprise
SpringOne Tour: An Introduction to Azure Spring Apps EnterpriseSpringOne Tour: An Introduction to Azure Spring Apps Enterprise
SpringOne Tour: An Introduction to Azure Spring Apps Enterprise
 
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
 
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.pptKKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
 
JBCN_Testing_With_Containers
JBCN_Testing_With_ContainersJBCN_Testing_With_Containers
JBCN_Testing_With_Containers
 
Ensuring Software Quality Through Test Automation- Naperville Software Develo...
Ensuring Software Quality Through Test Automation- Naperville Software Develo...Ensuring Software Quality Through Test Automation- Naperville Software Develo...
Ensuring Software Quality Through Test Automation- Naperville Software Develo...
 
Cypress Testing.pptx
Cypress Testing.pptxCypress Testing.pptx
Cypress Testing.pptx
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
 
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2
 

More from Sam Brannen

Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023Sam Brannen
 
Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022Sam Brannen
 
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019Sam Brannen
 
JUnit 5: What's New and What's Coming - Spring I/O 2019
JUnit 5: What's New and What's Coming - Spring I/O 2019JUnit 5: What's New and What's Coming - Spring I/O 2019
JUnit 5: What's New and What's Coming - Spring I/O 2019Sam Brannen
 
JUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVMJUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVMSam Brannen
 
Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2Sam Brannen
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondSam Brannen
 
Composable Software Architecture with Spring
Composable Software Architecture with SpringComposable Software Architecture with Spring
Composable Software Architecture with SpringSam Brannen
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Sam Brannen
 
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Sam Brannen
 
Spring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4DevelopersSpring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4DevelopersSam Brannen
 
Effective out-of-container Integration Testing - 4Developers
Effective out-of-container Integration Testing - 4DevelopersEffective out-of-container Integration Testing - 4Developers
Effective out-of-container Integration Testing - 4DevelopersSam Brannen
 
Spring 3.1 to 3.2 in a Nutshell - SDC2012
Spring 3.1 to 3.2 in a Nutshell - SDC2012Spring 3.1 to 3.2 in a Nutshell - SDC2012
Spring 3.1 to 3.2 in a Nutshell - SDC2012Sam Brannen
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSam Brannen
 
Spring 3.1 in a Nutshell
Spring 3.1 in a NutshellSpring 3.1 in a Nutshell
Spring 3.1 in a NutshellSam Brannen
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
 
What's New in Spring 3.0
What's New in Spring 3.0What's New in Spring 3.0
What's New in Spring 3.0Sam Brannen
 
Modular Web Applications with OSGi
Modular Web Applications with OSGiModular Web Applications with OSGi
Modular Web Applications with OSGiSam Brannen
 
Enterprise Applications With OSGi and SpringSource dm Server
Enterprise Applications With OSGi and SpringSource dm ServerEnterprise Applications With OSGi and SpringSource dm Server
Enterprise Applications With OSGi and SpringSource dm ServerSam Brannen
 

More from Sam Brannen (19)

Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
 
Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022
 
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
 
JUnit 5: What's New and What's Coming - Spring I/O 2019
JUnit 5: What's New and What's Coming - Spring I/O 2019JUnit 5: What's New and What's Coming - Spring I/O 2019
JUnit 5: What's New and What's Coming - Spring I/O 2019
 
JUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVMJUnit 5 - New Opportunities for Testing on the JVM
JUnit 5 - New Opportunities for Testing on the JVM
 
Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2Get the Most out of Testing with Spring 4.2
Get the Most out of Testing with Spring 4.2
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyond
 
Composable Software Architecture with Spring
Composable Software Architecture with SpringComposable Software Architecture with Spring
Composable Software Architecture with Spring
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1
 
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
 
Spring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4DevelopersSpring 3.1 and MVC Testing Support - 4Developers
Spring 3.1 and MVC Testing Support - 4Developers
 
Effective out-of-container Integration Testing - 4Developers
Effective out-of-container Integration Testing - 4DevelopersEffective out-of-container Integration Testing - 4Developers
Effective out-of-container Integration Testing - 4Developers
 
Spring 3.1 to 3.2 in a Nutshell - SDC2012
Spring 3.1 to 3.2 in a Nutshell - SDC2012Spring 3.1 to 3.2 in a Nutshell - SDC2012
Spring 3.1 to 3.2 in a Nutshell - SDC2012
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing Support
 
Spring 3.1 in a Nutshell
Spring 3.1 in a NutshellSpring 3.1 in a Nutshell
Spring 3.1 in a Nutshell
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
What's New in Spring 3.0
What's New in Spring 3.0What's New in Spring 3.0
What's New in Spring 3.0
 
Modular Web Applications with OSGi
Modular Web Applications with OSGiModular Web Applications with OSGi
Modular Web Applications with OSGi
 
Enterprise Applications With OSGi and SpringSource dm Server
Enterprise Applications With OSGi and SpringSource dm ServerEnterprise Applications With OSGi and SpringSource dm Server
Enterprise Applications With OSGi and SpringSource dm Server
 

Recently uploaded

DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 

Recently uploaded (20)

DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 

Testing with Spring: An Introduction

  • 1. Testing with Spring: An Introduction Sam Brannen @sam_brannen Spring eXchange | London, England | November 6, 2014 eXchange 2014
  • 2. 2 Sam Brannen •  Spring and Java Consultant @ Swiftmind •  Java Developer for over 15 years •  Spring Framework Core Committer since 2007 –  Component lead for spring-test •  Spring Trainer •  Speaker on Spring, Java, and testing •  Swiss Spring User Group Lead
  • 3. 3 Swiftmind Experts in Spring and Enterprise Java Areas of expertise •  Spring * •  Java EE •  Software Architecture •  Software Engineering Best Practices Where you find us •  Zurich, Switzerland •  @swiftmind •  http://www.swiftmind.com
  • 4. 4 A Show of Hands… ? ? ? ?
  • 5. 5 Agenda •  Unit testing •  Integration testing •  Context management and DI •  Transactions and SQL scripts •  Spring MVC and REST •  Q&A
  • 7. 7 Unit Tests •  are simple to set up •  use dynamic mocks or stubs for dependencies •  instantiate the SUT, execute the code, and assert expectations •  run fast •  but only test a single unit
  • 8. 8 Spring and Unit Testing •  POJO-based programming model –  Program to interfaces –  IoC / Dependency Injection –  Out-of-container testability –  Third-party mocking frameworks (Mockito, …) •  Spring testing mocks/stubs –  Servlet –  Portlet –  JNDI –  Spring Environment
  • 9. 9 EventService API public interface EventService { List<Event> findAll(); Event save(Event event); void delete(Event event); }
  • 10. 10 EventService Implementation (1/2) @Service @Transactional public class StandardEventService implements EventService { private final EventRepository repository; @Autowired public StandardEventService(EventRepository repository) { this.repository = repository; } // ...
  • 11. 11 EventService Implementation (2/2) public Event save(final Event event) { // additional business logic ... return repository.save(event); }
  • 12. 12 EventService Unit Test (1/2) public class StandardEventServiceTests { private StandardEventService service; private EventRepository repository; @Before public void setUp() { repository = mock(EventRepository.class); service = new StandardEventService(repository); }
  • 13. 13 EventService Unit Test (2/2) @Test public void save() { Event event = new Event(); event.setName("test event"); event.setDescription("testing"); given(repository.save(any(Event.class))) .willReturn(event); Event savedEvent = service.save(event); assertThat(savedEvent, is(equalTo(event))); }
  • 15. 15 Integration Tests •  test interactions between multiple components •  relatively easy to set up… •  without external system dependencies •  challenging to set up… •  with external system dependencies •  more challenging… •  if application code depends on the container
  • 16. 16 Integration Test Complexity Complexity Dependency no external systems external systems container
  • 17. 17 Modern Enterprise Java Apps •  Integrate with external systems •  SMTP, FTP, LDAP, RDBMS, Web Services, JMS •  Rely on container-provided functionality •  data sources, connection factories, transaction managers
  • 18. 18 Effective Integration Testing •  Fast •  Repeatable •  Automated •  Easy to configure •  Run out-of-container
  • 19. 19 Out-of-container •  Zero reliance on availability of external systems •  Can be run anywhere •  developer workstation •  CI server •  Approximate the production environment •  Embedded database •  In-memory SMTP server, FTP server, JMS broker
  • 21. 21 In a nutshell… The Spring TestContext Framework … provides annotation-driven unit and integration testing support that is agnostic of the testing framework in use … with a strong focus on convention over configuration and reasonable defaults that can be overridden through annotation-based configuration … and integrates with JUnit and TestNG out of the box.
  • 22. 22 Testimony “The Spring TestContext Framework is an excellent example of good annotation usage as it allows composition rather than inheritance.” - Costin Leau
  • 23. 23 Feature Set •  Context management and caching •  Dependency Injection of test fixtures •  Transaction management •  SQL script execution •  Spring MVC and REST •  Extension points for customization
  • 24. 24 Spring 2.5 Testing Themes •  @ContextConfiguration –  XML config files –  Context caching •  @TestExecutionListeners –  Dependency injection: @Autowired, etc. –  @DirtiesContext –  @Transactional, @BeforeTransaction, etc. •  SpringJUnit4ClassRunner •  Abstract base classes for JUnit and TestNG
  • 25. 25 Spring 3.x Testing Themes (1/2) •  Embedded databases –  <jdbc:embedded-database /> & <jdbc:initialize-database /> –  EmbeddedDatabaseBuilder & EmbeddedDatabaseFactoryBean •  @Configuration classes •  @ActiveProfiles •  ApplicationContextInitializers
  • 26. 26 Spring 3.x Testing Themes (2/2) •  @WebAppConfiguration –  Loading WebApplicationContexts –  Testing request- and session-scoped beans •  @ContextHierarchy –  Web, Batch, etc. •  Spring MVC Test framework –  Server-side MVC and REST tests –  Client-side REST tests
  • 27. 27 Spring 4.0 Testing Themes •  SocketUtils –  Scan for available UDP & TCP ports •  ActiveProfilesResolver API –  Programmatic alternative to static profile strings –  Set via resolver attribute in @ActiveProfiles •  Meta-annotation support for tests –  Attribute overrides (optional and required)
  • 28. 28 New in 4.1 – Context Config •  Context config with Groovy scripts •  Declarative configuration for test property sources –  @TestPropertySource
  • 29. 29 New in 4.1 – Transactions & SQL •  Programmatic test transaction management –  TestTransaction API •  Declarative SQL script execution –  @Sql, @SqlConfig, @SqlGroup •  Improved docs for transactional tests
  • 30. 30 New in 4.1 – TestExecutionListeners •  Automatic discovery of default TestExecutionListeners –  Uses SpringFactoriesLoader –  Already used by Spring Security •  Merging custom TestExecutionListeners with defaults –  @TestExecutionListeners(mergeMode= MERGE_WITH_DEFAULTS) –  Defaults to REPLACE_DEFAULTS
  • 31. 31 New in 4.1 – Spring MVC Test •  Assert JSON responses with JSON Assert –  Complements JSONPath support •  Create MockMvcBuilder recipes with MockMvcConfigurer –  Developed to apply Spring Security setup but can be used by anyone •  AsyncRestTemplate support in MockRestServiceServer –  For asynchronous client-side testing
  • 33. 33 @ContextConfiguration •  Declared on test class –  Inheritance supported but overridable –  Spring Boot: use @SpringApplicationConfiguration •  ContextLoader loads ApplicationContext based on: –  Configuration in annotation –  Or by detecting default configuration •  Supports: –  XML configuration files –  @Configuration classes –  Groovy scripts
  • 34. 34 @WebAppConfiguration •  Declared on test class •  Instructs Spring to load a WebApplicationContext for the test •  ServletTestExecutionListener ensures that Servlet API mocks are properly configured •  Most often used with the Spring MVC Test Framework
  • 35. 35 @ContextHierarchy •  Declared on test class –  Used with @ContextConfiguration •  Configures hierarchies of test application contexts –  Useful for Spring MVC, Spring Batch, etc.
  • 36. 36 @ActiveProfiles •  Declared on test class –  Used with @ContextConfiguration •  Configures which bean definition profiles should be active when the test’s ApplicationContext is loaded •  Active profiles can be configured: –  Declaratively within the annotation –  Or programmatically via a custom ActiveProfilesResolver
  • 37. 37 Context Caching •  The Spring TestContext Framework caches all application contexts within the same JVM process! •  Cache key is generated based on configuration in: –  @ContextConfiguration –  @ContextHierarchy –  @WebAppConfiguration –  @ActiveProfiles •  Use @DirtiesContext to remove a given test from the cache
  • 38. 38 Ex: Context Configuration @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextHierarchy({ @ContextConfiguration(classes = RootConfig.class), @ContextConfiguration(classes = WebConfig.class) }) @ActiveProfiles("dev") public class ControllerIntegrationTests { // ...
  • 40. 40 DI within Integration Tests •  Dependencies can be injected into a test instance from the test’s ApplicationContext •  Using @Autowired, @Inject, @PersistenceContext, etc. •  The ApplicationContext itself can also be injected into test instances… •  @Autowired ApplicationContext •  @Autowired WebApplicationContext
  • 41. 41 EventService Integration Test @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class EventServiceIntegrationTests { @Autowired EventService service; @Test public void save() { Event event = new Event("test event"); Event savedEvent = service.save(event); assertNotNull(savedEvent.getId()); // ... }
  • 43. 43 Transactions in Spring •  Spring-managed transactions: managed by Spring in the ApplicationContext –  @Transactional and AOP •  Application-managed transactions: managed programmatically within application code –  TransactionTemplate and TransactionSynchronizationManager •  Test-managed transactions: managed by the Spring TestContext Framework –  @Transactional on test classes and test methods –  Transaction is rolled back by default!
  • 44. 44 Ex: Declarative Tx Management in Tests @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @Transactional public class TransactionalTests { @Test public void withinTransaction() { /* ... */ } What if we want to stop & start the transaction within the test method?
  • 45. 45 TestTransaction API •  Static methods for interacting with test-managed transactions –  isActive() –  isFlaggedForRollback() –  flagForCommit() –  flagForRollback() –  end() –  start() query status change default rollback setting end: roll back or commit based on flag start: new tx with default rollback setting
  • 46. 46 Ex: Programmatic Tx Mgmt in Tests @Test public void withinTransaction() { // assert initial state in test database: assertNumUsers(2); deleteFromTables("user"); // changes to the database will be committed TestTransaction.flagForCommit(); TestTransaction.end(); assertNumUsers(0); TestTransaction.start(); // perform other actions against the database that will // be automatically rolled back after test completes... }
  • 48. 48 SQL Script Execution Options •  At ApplicationContext startup via: •  <jdbc> XML namespace •  EmbeddedDatabaseBuilder in Java Config •  Programmatically during tests with: •  ScriptUtils, ResourceDatabasePopulator, or abstract transactional base test classes for JUnit and TestNG •  Declaratively via @Sql, @SqlConfig, & @SqlGroup •  Per test method •  Per test class
  • 49. 49 Ex: Embedded Database in Java Config EmbeddedDatabase db = new EmbeddedDatabaseBuilder() .setType(H2) .setScriptEncoding("UTF-8") .ignoreFailedDrops(true) .addScript("schema.sql") .addScripts("user_data.sql", "country_data.sql") .build(); // ... db.shutdown();
  • 50. 50 Ex: Embedded Database in XML Config <jdbc:embedded-database id="dataSource" type="H2"> <jdbc:script location="classpath:/schema.sql" /> <jdbc:script location="classpath:/user_data.sql" /> </jdbc:embedded-database>
  • 51. 51 Ex: Populate Database in XML Config <jdbc:initialize-database data-source="dataSource"> <jdbc:script location="classpath:/schema_01.sql" /> <jdbc:script location="classpath:/schema_02.sql" /> <jdbc:script location="classpath:/data_01.sql" /> <jdbc:script location="classpath:/data_02.sql" /> </jdbc:initialize-database>
  • 52. 52 Ex: @Sql in Action @ContextConfiguration @Sql({ "schema1.sql", "data1.sql" }) public class SqlScriptsTests { @Test public void classLevelScripts() { /* ... */ } @Test @Sql({ "schema2.sql", "data2.sql" }) public void methodLevelScripts() { /* ... */ }
  • 53. 53 @Sql - Repeatable Annotation (Java 8) @Test @Sql( scripts="/test-schema.sql", config = @SqlConfig(commentPrefix = "`") @Sql("/user-data.sql") public void userTest() { // code that uses the test schema and test data } Schema uses custom syntax
  • 54. 54 @Sql wrapped in @SqlGroup (Java 6/7) @Test @SqlGroup({ @Sql( scripts="/test-schema.sql", config = @SqlConfig(commentPrefix = "`"), @Sql("/user-data.sql") }) public void userTest() { // code that uses the test schema and test data }
  • 55. 55 Spring MVC Test Framework
  • 56. 56 What is Spring MVC Test? •  Dedicated support for testing Spring MVC applications •  Fluent API •  Very easy to write •  Includes client and server-side support •  Servlet container not required
  • 57. 57 Details •  Included in spring-test module of Spring Framework 3.2 •  Builds on –  TestContext framework for loading Spring MVC configuration –  MockHttpServlet[Request|Response] and other mock types •  Server-side tests involve DispatcherServlet •  Client-side REST testing for code using RestTemplate
  • 58. 58 Ex: Web Integration Test (1/2) @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextHierarchy({ @ContextConfiguration(classes = RootConfig.class), @ContextConfiguration(classes = WebConfig.class) }) @ActiveProfiles("dev") public class ControllerIntegrationTests { @Autowired private WebApplicationContext wac; private MockMvc mockMvc; // ...
  • 59. 59 Ex: Web Integration Test (2/2) @Before public void setup() { this.mockMvc = MockMvcBuilders .webAppContextSetup(this.wac).build(); } @Test public void person() throws Exception { this.mockMvc.perform(get("/person/42") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().string("{"name":"Sam"}")); }
  • 61. 61 Spring Resources •  Spring Framework –  http://projects.spring.io/spring-framework •  Spring Guides –  http://spring.io/guides •  Spring Forums –  http://forum.spring.io •  Spring JIRA –  https://jira.spring.io •  Spring on GitHub –  https://github.com/spring-projects/spring-framework
  • 62. 62 Blogs •  Swiftmind Blog –  http://www.swiftmind.com/blog •  Spring Blog –  http://spring.io/blog
  • 63. 63 Q & A Sam Brannen twitter: @sam_brannen www.slideshare.net/sbrannen www.swiftmind.com