SlideShare une entreprise Scribd logo
1  sur  51
Testing basics for developers
Anton Udovychenko
1 1 / 2 0 1 3
Agenda
• Motivation
• Unit testing
• JUnit, Mockito, Hamcrest, JsTestDriver
• Integration testing
• Persistence testing, Arquillian
• Functional testing
• SoapUI, Selenium
• Q&A
Why should we care?
Automated testing
Functional
Integration
Unit
5%
15%
80%
Unit testing
Test small portions of production code
Confidence to change
Quick Feedback
Documentation
Functional
Integration
Unit
Unit testing
TestNG
JUnit lifecycle
1. @BeforeClass
2. For each @Test
a) Instanciate test class
b) @Before
c) Invoke the test
d) @After
3. @AfterClass
JUnit advanced
1. @Rule and @ClassRule
2. Parametrized
3. Mocks
4. Hamcrest
JUnit @Rule
public class MyRule implements TestRule {
@Override
public Statement apply( Statement base, Description description ) {
return new MyStatement( base );
}
}
JUnit @Rule
public class MyStatement extends Statement {
private final Statement base;
public MyStatement( Statement base ) {
this.base = base;
}
@Override
public void evaluate() throws Throwable {
System.out.println( "before" );
try {
base.evaluate();
} finally {
System.out.println( "after" );
}
}
}
public class MyRule implements TestRule {
@Override
public Statement apply( Statement base, Description description ) {
return new MyStatement( base );
}
}
JUnit @Rule
public class MyTest {
@Rule
public MyRule myRule = new MyRule();
@Test
public void testRun() {
System.out.println( "during" );
}
}
public class MyRule implements TestRule {
@Override
public Statement apply( Statement base, Description description ) {
return new MyStatement( base );
}
}
public class MyStatement extends Statement {
private final Statement base;
public MyStatement( Statement base ) {
this.base = base;
}
@Override
public void evaluate() throws Throwable {
System.out.println( "before" );
try {
base.evaluate();
} finally {
System.out.println( "after" );
}
}
}
JUnit @Rule
public class MyTest {
@Rule
public MyRule myRule = new MyRule();
@Test
public void testRun() {
System.out.println( "during" );
}
}
public class MyRule implements TestRule {
@Override
public Statement apply( Statement base, Description description ) {
return new MyStatement( base );
}
}
public class MyStatement extends Statement {
private final Statement base;
public MyStatement( Statement base ) {
this.base = base;
}
@Override
public void evaluate() throws Throwable {
System.out.println( "before" );
try {
base.evaluate();
} finally {
System.out.println( "after" );
}
}
}
Output:
before
during
after
JUnit @ClassRule
@RunWith(Suite.class)
@SuiteClasses({ TestCase1.class, TestCase2.class })
public class AllTests {
@ClassRule
public static Timeout timeout = new Timeout(3000);
}
JUnit Parametrized
@RunWith(value = Parameterized.class)
public class MyTest {
private int number;
public MyTest(int number) {
this.number = number;
}
@Parameters
public static Collection<Object[]> data() {
Object[][] data = new Object[][] { { 1 }, { 2 }, { 3 }, { 4 } };
return Arrays.asList(data);
}
@Test
public void pushTest() {
System.out.println("Parameterized Number is : " + number);
}
}
Mockito
Mockito is a mocking framework for unit tests in Java
Mockito
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
import java.util.Iterator;
import org.junit.Test;
....
@Test
public void iteratorWillReturnHelloWorld(){
//arrange
Iterator i=mock(Iterator.class);
when(i.next()).thenReturn("Hello").thenReturn("World");
//act
String result=i.next()+" "+i.next();
//assert
assertEquals("Hello World", result);
}
Hamcrest
Hamcrest is a matchers framework that assists writing software tests
Hamcrest
assertTrue(foo.contains("someValue") && foo.contains("anotherValue"));
Hamcrest
assertTrue(foo.contains("someValue") && foo.contains("anotherValue"));
assertThat(foo, hasItems("someValue", "anotherValue"));
vs
Hamcrest
assertTrue(foo.contains("someValue") && foo.contains("anotherValue"));
assertThat(foo, hasItems("someValue", "anotherValue"));
vs
assertThat(
table,
column("Type",contains("A","B","C")).where(cell("Status", is("Ok")))
);
Another example:
JsTestDriver
JsTestDriver is an open source JavaScript unit tests runner
JsTestDriver
Integration testing
Test collaboration between components
Database
IO system
Special environment configuration
Functional
Integration
Unit
Persistence testing
In memory databases
DBUnit
Arquillian
Arquillian is a platform that simplifies integration testing for Java middleware
Arquillian
• Real Tests (no mocks)
Arquillian
• Real Tests (no mocks)
• IDE Friendly
Arquillian
• Real Tests (no mocks)
• IDE Friendly
• Test Enrichment
Arquillian
• Real Tests (no mocks)
• IDE Friendly
• Test Enrichment
• Classpath Control
Arquillian
• Real Tests (no mocks)
• IDE Friendly
• Test Enrichment
• Classpath Control
• Drive the Browser
Arquillian
• Real Tests (no mocks)
• IDE Friendly
• Test Enrichment
• Classpath Control
• Drive the Browser
• Debug the Server
Arquillian
• Real Tests (no mocks)
• IDE Friendly
• Test Enrichment
• Classpath Control
• Drive the Browser
• Debug the Server
• Container agnostic
Arquillian
• Real Tests (no mocks)
• IDE Friendly
• Test Enrichment
• Classpath Control
• Drive the Browser
• Debug the Server
• Container agnostic
• Extensible platform
Arquillian
public class Greeter {
public void greet(PrintStream to, String name) {
to.println(createGreeting(name));
}
public String createGreeting(String name) {
return "Hello, " + name + "!";
}
}
Arquillian
public class Greeter {
public void greet(PrintStream to, String name) {
to.println(createGreeting(name));
}
public String createGreeting(String name) {
return "Hello, " + name + "!";
}
}
@RunWith(Arquillian.class)
public class GreeterTest {
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class)
.addClass(Greeter.class)
.addAsManifestResource(EmptyAsset.INSTANCE,
"beans.xml");
}
@Inject
Greeter greeter;
@Test
public void should_create_greeting() {
Assert.assertEquals("Hello, Earthling!",
greeter.createGreeting("Earthling"));
}
}
Functional testing
Test customer requirements
Functional
Integration
Unit
SoapUI
SoapUI is a web service testing application
SoapUI
• Main technologies: SOAP, REST, XML-RPC, HTTP(S), AMF, JDBC, JMS
SoapUI is a web service testing application
SoapUI
• Main technologies: SOAP, REST, XML-RPC, HTTP(S), AMF, JDBC, JMS
• Allows security and load testing
SoapUI is a web service testing application
SoapUI
• Main technologies: SOAP, REST, XML-RPC, HTTP(S), AMF, JDBC, JMS
• Allows security and load testing
• Service mocking
SoapUI is a web service testing application
SoapUI
• Main technologies: SOAP, REST, XML-RPC, HTTP(S), AMF, JDBC, JMS
• Allows security and load testing
• Service mocking
• Logging of the test results
SoapUI is a web service testing application
SoapUI
• Main technologies: SOAP, REST, XML-RPC, HTTP(S), AMF, JDBC, JMS
• Allows security and load testing
• Service mocking
• Logging of the test results
• Groovy API
SoapUI is a web service testing application
SoapUI
public void testTestCaseRunner() throws Exception {
WsdlProject project = new WsdlProject( "src/dist/sample-soapui-project.xml" );
TestSuite testSuite = project.getTestSuiteByName( "Test Suite" );
TestCase testCase = testSuite.getTestCaseByName( "Test Conversions" );
// create empty properties and run synchronously
TestRunner runner = testCase.run( new PropertiesMap(), false );
assertEquals( Status.FINISHED, runner.getStatus() );
}
Selenium
Selenium is a portable software GUI testing framework for web applications
Selenium
• Domain specific language (DSL): Java, C#, Groovy, Perl, PHP, Python and Ruby.
Selenium is a portable software GUI testing framework for web applications
Selenium
• Domain specific language (DSL): Java, C#, Groovy, Perl, PHP, Python and Ruby.
• The tests can then be run against most modern web browsers
Selenium is a portable software GUI testing framework for web applications
Selenium
• Domain specific language (DSL): Java, C#, Groovy, Perl, PHP, Python and Ruby.
• The tests can then be run against most modern web browsers
• Selenium deploys on Windows, Linux, and Macintosh platforms
Selenium is a portable software GUI testing framework for web applications
Selenium
• Domain specific language (DSL): Java, C#, Groovy, Perl, PHP, Python and Ruby.
• The tests can then be run against most modern web browsers
• Selenium deploys on Windows, Linux, and Macintosh platforms
• Selenium provides a record/playback tool for authoring tests without learning a test
scripting language (Selenium IDE)
Selenium is a portable software GUI testing framework for web applications
Selenium
public class Selenium2Example {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
};
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
Summary
Functional
Integration
Unit
5%
15%
80%
TestNG
Hamcrest
Questions?

Contenu connexe

Tendances

Android Unit Test
Android Unit TestAndroid Unit Test
Android Unit TestPhuoc Bui
 
Appium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation ExecutionAppium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation ExecutionpCloudy
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript TestingKissy Team
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modulesRafael Winterhalter
 
Java8 tgtbatu javaone
Java8 tgtbatu javaoneJava8 tgtbatu javaone
Java8 tgtbatu javaoneBrian Vermeer
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Tomek Kaczanowski
 
Implementing quality in Java projects
Implementing quality in Java projectsImplementing quality in Java projects
Implementing quality in Java projectsVincent Massol
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Kirill Rozov
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languagesRafael Winterhalter
 
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, howTomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, howTomasz Polanski
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCPEric Jain
 
Just Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingJust Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingOrtus Solutions, Corp
 
Unit testing with Qt test
Unit testing with Qt testUnit testing with Qt test
Unit testing with Qt testDavide Coppola
 
Scaladays 2014 introduction to scalatest selenium dsl
Scaladays 2014   introduction to scalatest selenium dslScaladays 2014   introduction to scalatest selenium dsl
Scaladays 2014 introduction to scalatest selenium dslMatthew Farwell
 

Tendances (19)

Android Unit Test
Android Unit TestAndroid Unit Test
Android Unit Test
 
Java Quiz Questions
Java Quiz QuestionsJava Quiz Questions
Java Quiz Questions
 
Appium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation ExecutionAppium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation Execution
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testing
 
Testing with PostgreSQL
Testing with PostgreSQLTesting with PostgreSQL
Testing with PostgreSQL
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modules
 
Java8 tgtbatu javaone
Java8 tgtbatu javaoneJava8 tgtbatu javaone
Java8 tgtbatu javaone
 
Java Quiz - Meetup
Java Quiz - MeetupJava Quiz - Meetup
Java Quiz - Meetup
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010
 
Implementing quality in Java projects
Implementing quality in Java projectsImplementing quality in Java projects
Implementing quality in Java projects
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1
 
Qunit Java script Un
Qunit Java script UnQunit Java script Un
Qunit Java script Un
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
 
Junit With Eclipse
Junit With EclipseJunit With Eclipse
Junit With Eclipse
 
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, howTomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCP
 
Just Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingJust Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration Testing
 
Unit testing with Qt test
Unit testing with Qt testUnit testing with Qt test
Unit testing with Qt test
 
Scaladays 2014 introduction to scalatest selenium dsl
Scaladays 2014   introduction to scalatest selenium dslScaladays 2014   introduction to scalatest selenium dsl
Scaladays 2014 introduction to scalatest selenium dsl
 

En vedette

Writing quick and beautiful automation code
Writing quick and beautiful automation codeWriting quick and beautiful automation code
Writing quick and beautiful automation codeCristian COȚOI
 
Writing and using Hamcrest Matchers
Writing and using Hamcrest MatchersWriting and using Hamcrest Matchers
Writing and using Hamcrest MatchersShai Yallin
 
Design principles in a nutshell
Design principles in a nutshellDesign principles in a nutshell
Design principles in a nutshellAnton Udovychenko
 
Microservices: a journey of an eternal improvement
Microservices: a journey of an eternal improvementMicroservices: a journey of an eternal improvement
Microservices: a journey of an eternal improvementAnton Udovychenko
 
Load-testing 101 for Startups with Artillery.io
Load-testing 101 for Startups with Artillery.ioLoad-testing 101 for Startups with Artillery.io
Load-testing 101 for Startups with Artillery.ioHassy Veldstra
 
Search and analyze your data with elasticsearch
Search and analyze your data with elasticsearchSearch and analyze your data with elasticsearch
Search and analyze your data with elasticsearchAnton Udovychenko
 
Going Serverless with CQRS on AWS
Going Serverless with CQRS on AWSGoing Serverless with CQRS on AWS
Going Serverless with CQRS on AWSAnton Udovychenko
 
Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)Chris Richardson
 
Microservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event SourcingMicroservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event SourcingBen Wilcock
 
Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Building and deploying microservices with event sourcing, CQRS and Docker (QC...Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Building and deploying microservices with event sourcing, CQRS and Docker (QC...Chris Richardson
 
Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Chris Richardson
 
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...Chris Richardson
 

En vedette (14)

Writing quick and beautiful automation code
Writing quick and beautiful automation codeWriting quick and beautiful automation code
Writing quick and beautiful automation code
 
Android Espresso
Android EspressoAndroid Espresso
Android Espresso
 
Writing and using Hamcrest Matchers
Writing and using Hamcrest MatchersWriting and using Hamcrest Matchers
Writing and using Hamcrest Matchers
 
Design principles in a nutshell
Design principles in a nutshellDesign principles in a nutshell
Design principles in a nutshell
 
Microservices: a journey of an eternal improvement
Microservices: a journey of an eternal improvementMicroservices: a journey of an eternal improvement
Microservices: a journey of an eternal improvement
 
Load-testing 101 for Startups with Artillery.io
Load-testing 101 for Startups with Artillery.ioLoad-testing 101 for Startups with Artillery.io
Load-testing 101 for Startups with Artillery.io
 
Search and analyze your data with elasticsearch
Search and analyze your data with elasticsearchSearch and analyze your data with elasticsearch
Search and analyze your data with elasticsearch
 
Going Serverless with CQRS on AWS
Going Serverless with CQRS on AWSGoing Serverless with CQRS on AWS
Going Serverless with CQRS on AWS
 
Choosing Hippo CMS
Choosing Hippo CMSChoosing Hippo CMS
Choosing Hippo CMS
 
Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)
 
Microservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event SourcingMicroservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event Sourcing
 
Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Building and deploying microservices with event sourcing, CQRS and Docker (QC...Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Building and deploying microservices with event sourcing, CQRS and Docker (QC...
 
Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)
 
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
 

Similaire à Testing basics for developers

JUnit5 and TestContainers
JUnit5 and TestContainersJUnit5 and TestContainers
JUnit5 and TestContainersSunghyouk Bae
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instrumentsArtem Nagornyi
 
Guide to the jungle of testing frameworks
Guide to the jungle of testing frameworksGuide to the jungle of testing frameworks
Guide to the jungle of testing frameworksTomáš Kypta
 
Guide to the jungle of testing frameworks
Guide to the jungle of testing frameworksGuide to the jungle of testing frameworks
Guide to the jungle of testing frameworksTomáš Kypta
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFXHendrik Ebbers
 
Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5Jimmy Lu
 
Testing in android
Testing in androidTesting in android
Testing in androidjtrindade
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotationjavatwo2011
 
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...JAXLondon2014
 
Testing the Enterprise layers, with Arquillian
Testing the Enterprise layers, with ArquillianTesting the Enterprise layers, with Arquillian
Testing the Enterprise layers, with ArquillianVirtual JBoss User Group
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Testing Java Code Effectively
Testing Java Code EffectivelyTesting Java Code Effectively
Testing Java Code EffectivelyAndres Almiray
 
How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?Dmitry Buzdin
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And DrupalPeter Arato
 

Similaire à Testing basics for developers (20)

JUnit5 and TestContainers
JUnit5 and TestContainersJUnit5 and TestContainers
JUnit5 and TestContainers
 
Good Practices On Test Automation
Good Practices On Test AutomationGood Practices On Test Automation
Good Practices On Test Automation
 
Junit_.pptx
Junit_.pptxJunit_.pptx
Junit_.pptx
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instruments
 
Guide to the jungle of testing frameworks
Guide to the jungle of testing frameworksGuide to the jungle of testing frameworks
Guide to the jungle of testing frameworks
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Guide to the jungle of testing frameworks
Guide to the jungle of testing frameworksGuide to the jungle of testing frameworks
Guide to the jungle of testing frameworks
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
TestNG
TestNGTestNG
TestNG
 
Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5
 
Testing in android
Testing in androidTesting in android
Testing in android
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
 
Testing the Enterprise layers, with Arquillian
Testing the Enterprise layers, with ArquillianTesting the Enterprise layers, with Arquillian
Testing the Enterprise layers, with Arquillian
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Testing Java Code Effectively
Testing Java Code EffectivelyTesting Java Code Effectively
Testing Java Code Effectively
 
Advanced Java Testing
Advanced Java TestingAdvanced Java Testing
Advanced Java Testing
 
How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
 

Dernier

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 

Dernier (20)

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 

Testing basics for developers

  • 1. Testing basics for developers Anton Udovychenko 1 1 / 2 0 1 3
  • 2. Agenda • Motivation • Unit testing • JUnit, Mockito, Hamcrest, JsTestDriver • Integration testing • Persistence testing, Arquillian • Functional testing • SoapUI, Selenium • Q&A
  • 5. Unit testing Test small portions of production code Confidence to change Quick Feedback Documentation Functional Integration Unit
  • 7. JUnit lifecycle 1. @BeforeClass 2. For each @Test a) Instanciate test class b) @Before c) Invoke the test d) @After 3. @AfterClass
  • 8. JUnit advanced 1. @Rule and @ClassRule 2. Parametrized 3. Mocks 4. Hamcrest
  • 9. JUnit @Rule public class MyRule implements TestRule { @Override public Statement apply( Statement base, Description description ) { return new MyStatement( base ); } }
  • 10. JUnit @Rule public class MyStatement extends Statement { private final Statement base; public MyStatement( Statement base ) { this.base = base; } @Override public void evaluate() throws Throwable { System.out.println( "before" ); try { base.evaluate(); } finally { System.out.println( "after" ); } } } public class MyRule implements TestRule { @Override public Statement apply( Statement base, Description description ) { return new MyStatement( base ); } }
  • 11. JUnit @Rule public class MyTest { @Rule public MyRule myRule = new MyRule(); @Test public void testRun() { System.out.println( "during" ); } } public class MyRule implements TestRule { @Override public Statement apply( Statement base, Description description ) { return new MyStatement( base ); } } public class MyStatement extends Statement { private final Statement base; public MyStatement( Statement base ) { this.base = base; } @Override public void evaluate() throws Throwable { System.out.println( "before" ); try { base.evaluate(); } finally { System.out.println( "after" ); } } }
  • 12. JUnit @Rule public class MyTest { @Rule public MyRule myRule = new MyRule(); @Test public void testRun() { System.out.println( "during" ); } } public class MyRule implements TestRule { @Override public Statement apply( Statement base, Description description ) { return new MyStatement( base ); } } public class MyStatement extends Statement { private final Statement base; public MyStatement( Statement base ) { this.base = base; } @Override public void evaluate() throws Throwable { System.out.println( "before" ); try { base.evaluate(); } finally { System.out.println( "after" ); } } } Output: before during after
  • 13. JUnit @ClassRule @RunWith(Suite.class) @SuiteClasses({ TestCase1.class, TestCase2.class }) public class AllTests { @ClassRule public static Timeout timeout = new Timeout(3000); }
  • 14. JUnit Parametrized @RunWith(value = Parameterized.class) public class MyTest { private int number; public MyTest(int number) { this.number = number; } @Parameters public static Collection<Object[]> data() { Object[][] data = new Object[][] { { 1 }, { 2 }, { 3 }, { 4 } }; return Arrays.asList(data); } @Test public void pushTest() { System.out.println("Parameterized Number is : " + number); } }
  • 15. Mockito Mockito is a mocking framework for unit tests in Java
  • 16. Mockito import static org.mockito.Mockito.*; import static org.junit.Assert.*; import java.util.Iterator; import org.junit.Test; .... @Test public void iteratorWillReturnHelloWorld(){ //arrange Iterator i=mock(Iterator.class); when(i.next()).thenReturn("Hello").thenReturn("World"); //act String result=i.next()+" "+i.next(); //assert assertEquals("Hello World", result); }
  • 17. Hamcrest Hamcrest is a matchers framework that assists writing software tests
  • 20. Hamcrest assertTrue(foo.contains("someValue") && foo.contains("anotherValue")); assertThat(foo, hasItems("someValue", "anotherValue")); vs assertThat( table, column("Type",contains("A","B","C")).where(cell("Status", is("Ok"))) ); Another example:
  • 21. JsTestDriver JsTestDriver is an open source JavaScript unit tests runner
  • 23. Integration testing Test collaboration between components Database IO system Special environment configuration Functional Integration Unit
  • 24. Persistence testing In memory databases DBUnit
  • 25. Arquillian Arquillian is a platform that simplifies integration testing for Java middleware
  • 27. Arquillian • Real Tests (no mocks) • IDE Friendly
  • 28. Arquillian • Real Tests (no mocks) • IDE Friendly • Test Enrichment
  • 29. Arquillian • Real Tests (no mocks) • IDE Friendly • Test Enrichment • Classpath Control
  • 30. Arquillian • Real Tests (no mocks) • IDE Friendly • Test Enrichment • Classpath Control • Drive the Browser
  • 31. Arquillian • Real Tests (no mocks) • IDE Friendly • Test Enrichment • Classpath Control • Drive the Browser • Debug the Server
  • 32. Arquillian • Real Tests (no mocks) • IDE Friendly • Test Enrichment • Classpath Control • Drive the Browser • Debug the Server • Container agnostic
  • 33. Arquillian • Real Tests (no mocks) • IDE Friendly • Test Enrichment • Classpath Control • Drive the Browser • Debug the Server • Container agnostic • Extensible platform
  • 34. Arquillian public class Greeter { public void greet(PrintStream to, String name) { to.println(createGreeting(name)); } public String createGreeting(String name) { return "Hello, " + name + "!"; } }
  • 35. Arquillian public class Greeter { public void greet(PrintStream to, String name) { to.println(createGreeting(name)); } public String createGreeting(String name) { return "Hello, " + name + "!"; } } @RunWith(Arquillian.class) public class GreeterTest { @Deployment public static JavaArchive createDeployment() { return ShrinkWrap.create(JavaArchive.class) .addClass(Greeter.class) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); } @Inject Greeter greeter; @Test public void should_create_greeting() { Assert.assertEquals("Hello, Earthling!", greeter.createGreeting("Earthling")); } }
  • 36. Functional testing Test customer requirements Functional Integration Unit
  • 37. SoapUI SoapUI is a web service testing application
  • 38. SoapUI • Main technologies: SOAP, REST, XML-RPC, HTTP(S), AMF, JDBC, JMS SoapUI is a web service testing application
  • 39. SoapUI • Main technologies: SOAP, REST, XML-RPC, HTTP(S), AMF, JDBC, JMS • Allows security and load testing SoapUI is a web service testing application
  • 40. SoapUI • Main technologies: SOAP, REST, XML-RPC, HTTP(S), AMF, JDBC, JMS • Allows security and load testing • Service mocking SoapUI is a web service testing application
  • 41. SoapUI • Main technologies: SOAP, REST, XML-RPC, HTTP(S), AMF, JDBC, JMS • Allows security and load testing • Service mocking • Logging of the test results SoapUI is a web service testing application
  • 42. SoapUI • Main technologies: SOAP, REST, XML-RPC, HTTP(S), AMF, JDBC, JMS • Allows security and load testing • Service mocking • Logging of the test results • Groovy API SoapUI is a web service testing application
  • 43. SoapUI public void testTestCaseRunner() throws Exception { WsdlProject project = new WsdlProject( "src/dist/sample-soapui-project.xml" ); TestSuite testSuite = project.getTestSuiteByName( "Test Suite" ); TestCase testCase = testSuite.getTestCaseByName( "Test Conversions" ); // create empty properties and run synchronously TestRunner runner = testCase.run( new PropertiesMap(), false ); assertEquals( Status.FINISHED, runner.getStatus() ); }
  • 44. Selenium Selenium is a portable software GUI testing framework for web applications
  • 45. Selenium • Domain specific language (DSL): Java, C#, Groovy, Perl, PHP, Python and Ruby. Selenium is a portable software GUI testing framework for web applications
  • 46. Selenium • Domain specific language (DSL): Java, C#, Groovy, Perl, PHP, Python and Ruby. • The tests can then be run against most modern web browsers Selenium is a portable software GUI testing framework for web applications
  • 47. Selenium • Domain specific language (DSL): Java, C#, Groovy, Perl, PHP, Python and Ruby. • The tests can then be run against most modern web browsers • Selenium deploys on Windows, Linux, and Macintosh platforms Selenium is a portable software GUI testing framework for web applications
  • 48. Selenium • Domain specific language (DSL): Java, C#, Groovy, Perl, PHP, Python and Ruby. • The tests can then be run against most modern web browsers • Selenium deploys on Windows, Linux, and Macintosh platforms • Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE) Selenium is a portable software GUI testing framework for web applications
  • 49. Selenium public class Selenium2Example { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com"); WebElement element = driver.findElement(By.name("q")); element.sendKeys("Cheese!"); element.submit(); System.out.println("Page title is: " + driver.getTitle()); new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }; System.out.println("Page title is: " + driver.getTitle()); driver.quit(); } }