69
Integration Testing Awesome subtitle

Integration testing - A&BP CC

Embed Size (px)

Citation preview

Page 1: Integration testing - A&BP CC

Integration TestingAwesome subtitle

Page 2: Integration testing - A&BP CC

Integration TestingAwesome subtitle

Page 3: Integration testing - A&BP CC

Integration TestingAwesome subtitle

Page 4: Integration testing - A&BP CC

Integration TestingAwesome subtitle

Page 5: Integration testing - A&BP CC

Testing

▪ Unit testing▪ Integration testing▪ System Integration testing▪ Load testing▪ Performance testing▪ User acceptance testing

Page 6: Integration testing - A&BP CC

Overview

1. Testing Terminologies

2. Component Integration Testing

a. Persistence tests

b. Container tests

c. Other component integrations

3. System Integration Testing

Page 7: Integration testing - A&BP CC

Testing terminologies

Page 8: Integration testing - A&BP CC

Test levels/phases

Requirement Specification Acceptance Testing

Functional Analysis System Testing

Technical Design Integration Testing

Coding Component Testing

System Integration Testing

Component Integration Testing

BB

WB

Page 9: Integration testing - A&BP CC

Test characteristics

▪ Connectivity▪ Continuity▪ Data controllability▪ Effectivity▪ Efficiency▪ Flexibility▪ Functionality▪ Suitability of infrastructure▪ Maintainability▪ Manageability▪ Performance▪ Portability▪ Reusability▪ Security▪ Suitability▪ Testability▪ User-friendliness

Page 10: Integration testing - A&BP CC

Focus on terminology

▪ Dedicated test environments

▪ Sanity tests (smoke tests)

▪ Regression testing

▪ Combinations and boundaries

▪ Positive and negative

▪ Valid and invalid

▪ End 2 End testing (chain testing)

▪ Performance testing (load testing vs. stress testing)

▪ Manual testing vs. test automation

Page 11: Integration testing - A&BP CC

Component Integration Testing

Page 12: Integration testing - A&BP CC

Component Integration Testing

Demo:▪ Service Layer going to Database Layer

Page 13: Integration testing - A&BP CC

PERSISTENCE TESTS

Page 14: Integration testing - A&BP CC

Persistence Tests

Using real databases for tests:▪ slow▪ harder than it should be▪ separate schemas per user?▪ network required

Using local database for tests:▪ even slower▪ requires (annoying) installation▪ no network required

Page 15: Integration testing - A&BP CC

Persistence Tests

Using in-memory database for tests:▪ super fast▪ only lives during test▪ allows for very specific test data▪ can be upgraded/changed/...

Page 16: Integration testing - A&BP CC

Persistence Tests

Demo:▪ JPA2 via Hibernate▪ Spring Data▪ SpringJUnit4ClassRunner▪ DBUnit

Page 17: Integration testing - A&BP CC

Persistence Tests

Demo:▪ JPA2 via Hibernate▪ Spring Data▪ SpringJUnit4ClassRunner▪ DBUnit▪ + Spring MVC (REST client)▪ + Selenium (Chrome WebDriver)

Page 18: Integration testing - A&BP CC

CONTAINER TESTS

Page 19: Integration testing - A&BP CC

What is a container?

Page 20: Integration testing - A&BP CC

What is a container?

A Java ecosystem in which an application is managed

life-cycletransactionspersistencesecurity...

Page 21: Integration testing - A&BP CC

What is a container?

DI container (Dependency Injection)EJB container (Enterprise Java Beans)

Web containerApplication client container

Applet container

Page 22: Integration testing - A&BP CC

Most known providers today

Page 23: Integration testing - A&BP CC

Most known providers today

▪ Only provides a DI Container: IoC (inversion of control)▪ Runs anywhere▪ No application server needed

Page 24: Integration testing - A&BP CC

Most known providers today

Page 25: Integration testing - A&BP CC

Most known providers today

▪ Provides specifications for:▪ DI container: CDI (Contexts and Dependency Injection)▪ EJB container▪ Web container▪ Application client container▪ Applet container

▪ It only runs on an application server implementing these specs.

Page 26: Integration testing - A&BP CC

What to test?

Dependency Injection (is everything wired correctly together?)▪ Application Context

▪ CDI

Page 27: Integration testing - A&BP CC

What to test?

Persistence: and : is JPA (Java Persistence API) mapping correct?

Page 28: Integration testing - A&BP CC

What to test?

Transaction Management:▪ : Spring Transaction

▪ : JTA (Java Transaction API)

Page 29: Integration testing - A&BP CC

What to test?

Deployment:▪ : no deployment needed (not to test)

▪ : will it deploy without exceptions in a real Java EE container?

Page 30: Integration testing - A&BP CC

How?

Container-tests

Page 31: Integration testing - A&BP CC

How?

out of the box

@RunWith(SpringJUnit4ClassRunner.class)@SpringApplicationConfiguration(classes = Application.class)@Transactionalpublic class SpringIntegrationTest {

Really, that easy :-) !!

Page 32: Integration testing - A&BP CC

How?

not out of the box

Need for third-party frameworks

Page 33: Integration testing - A&BP CC

How?

OpenEJB: a lightweight embeddable EJB containerCan be used with JUnit

Page 34: Integration testing - A&BP CC

How?

A lot to write

Page 35: Integration testing - A&BP CC

How?

And more:

Page 36: Integration testing - A&BP CC

How?

Arquillian:▪ Embeddable containers for JUnit-tests▪ Run tests in real running containers

The real thing application servers:GlassfishJbossWeblogic...

Page 37: Integration testing - A&BP CC

How?

All it takes in Arquillian@RunWith(Arquillian.class)public class ArquillianIntegrationTest { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war") .addPackage(MeetingRoom.class.getPackage()) .addPackage(MeetingOrganizer.class.getPackage()) .addPackage(MeetingRoomRepository.class.getPackage()) .addAsResource("persistence-test.xml", "META-INF/persistence.xml") .addAsWebInfResource("jbossas-ds.xml") .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); }

Actually, together with xml config, but pretty straight-forward

Page 38: Integration testing - A&BP CC

Demo

Integration testwiringtransactional test

Integration testwiringtransactional testweb integration test with Graphene

https://github.com/brunobouko

Page 39: Integration testing - A&BP CC

OTHER COMPONENT INTEGRATIONS

Page 40: Integration testing - A&BP CC

File Permissions

Page 41: Integration testing - A&BP CC

How to test ?

● Via dedicated checkFilePermission fp = new FilePermission("file.txt", "read");AccessController.checkPermission(fp);

● Via shell scriptsCheck you have staff group and file is readable by staff

[~] % ls -l file.txt | awk '{ print $1" "$3" "$4;}'\ | egrep -e '....r..... .* staff' >|/dev/null && echo 'ok' || echo 'ko' ok ● Manually...

Page 42: Integration testing - A&BP CC

Results

Page 43: Integration testing - A&BP CC

Emails

Page 44: Integration testing - A&BP CC

How to test

● With developer controlled server● With code

○ Spring Integration: https://github.com/spring-projects/spring-integration-samples/tree/master/basic/mail● With dedicated tools

Eg: Sending emails could use FakeSMTP - http://nilhcem.github.io/FakeSMTP● Running fake mail server during tests

○ GreenMail - http://www.icegreen.com/greenmail/

Roll the demo in: SendAMail project + GreenMailhttps://github.com/pijalu/SendAMail.git

Page 45: Integration testing - A&BP CC

JMS

Page 46: Integration testing - A&BP CC

How to test ?

● Writing test code○ ActiveMQ - http://activemq.apache.org/how-to-unit-test-jms-code.html○ Spring Integration- https://github.com/spring-projects/spring-integration-

samples/tree/master/basic/jms

● Using tools○ HermesJMS - http://www.hermesjms.com/confluence/display/HJMS/Home

■ Allows to post message on queues/topics■ Observes topics !

● With containers test enabled test like Arquillian

Roll the demo in: EJBees project with Arquillian !https://github.com/pijalu/ejbees.git

Page 47: Integration testing - A&BP CC

LDAP (and co)

Page 48: Integration testing - A&BP CC

How to test ?

● With tools○ Spring security

■ It can run a “test” LDAP server based on a LDIF file

○ Apache Directory Studio■ Allows to connect and browse to LDAP server (and AD is LDAP, but weird one...)■ Allows to run your own LDAP server for integration■ Allows to run your own LDAP server within JUnit tests

Roll the Demo in: LDAP Dance

https://github.com/pijalu/ldapdance

Page 49: Integration testing - A&BP CC

SOAP/REST/WS/...

Page 50: Integration testing - A&BP CC

How to test ?

● Writing your own integration tests● Using tools

○ SoapUI■ Can call the service■ Perform tests■ Can run with maven

Roll the demo in: SoapUI + SoapUI project !

https://github.com/pijalu/SoapUIDemo.git

Page 51: Integration testing - A&BP CC

Questions on other components tests ?

Page 52: Integration testing - A&BP CC

Environments

Page 53: Integration testing - A&BP CC

Environment - Disclaimer

● Commonly used● Not exact● Merged environments

Page 54: Integration testing - A&BP CC

Environment - Local

● typical laptop/desktop● focus on work at hand● not representative (resources, data volume)● maybe even different application server● mostly expecting unlimited resources● limited constraints● frequent deployments● possibly different os● possibly different settings (regional settings)

➔ goal: get your tasks completed➔ target users: developer

Page 55: Integration testing - A&BP CC

Environment - Component Integration (DEV)

● more limited within company standards● possibly increased complexity (authentication required)● automated deployment?● actual application server● possible dummy systems● mostly not load balanced

➔ goal: will it deploy on the actual infrastructure, sanity testing➔ target users: developers➔ challenge: bug free (and retard-proof)

Page 56: Integration testing - A&BP CC

Environment - System Integration (INT)

● representative systems● possibly reduced data● possibly load balanced● whatsup

➔ goal: does it work well combined with other systems?➔ target users: developers, testers

Page 57: Integration testing - A&BP CC

Environment - System Testing (TEST)

● representative systems● possibly reduced data● possibly load balanced

➔ goal: is it ready to present to business?➔ target users: testers, functional analysts➔ challenge: find the bugs!

Page 58: Integration testing - A&BP CC

Environment - User Acceptance Test (UAT)

● almost the real deal● no impact on end users● preferably identical setup compared to production● loadbalanced

➔ goal: does it meet the business requirements we've specified? do we need to rethink something? is this performant enough?

➔ target users: business users

Page 59: Integration testing - A&BP CC

Environment - Production

● the real deal● impact on end users

➔ target users: end users

Page 60: Integration testing - A&BP CC

Environment - Disaster Recovery

● mirror● offline● alternate site● pre go-live

Page 61: Integration testing - A&BP CC

System Integration Testing

Page 62: Integration testing - A&BP CC

System Integration Testing - What?

● web applications● desktop applications● mobile applications● embedded applications● headless applications● others?

Page 63: Integration testing - A&BP CC

System Integration Testing - How?

● manual testing● manual tools

○ soap ui○ db tools ○ ldap browser

● automated tools○ proprietary○ selenium○ custom made

Page 64: Integration testing - A&BP CC

System Integration Testing - Web application

● browser dependant● device dependant● subjective testing● subject to change

Page 65: Integration testing - A&BP CC

System Integration Testing - Web application

● browser dependant● device dependant● subjective testing● subject to change

Page 66: Integration testing - A&BP CC

System Integration Testing - Selenium

● target specific browser version● browser bugs● user simulation● reusability● screenshots

➔ record/replay◆ limited usability◆ parametrize!

➔ use static ids➔ html only

Page 67: Integration testing - A&BP CC

System Integration Testing - Headless browser

● faster● not 100% representative● prepare test cases● url check● javascript check● objective

➔ karma➔ jasmine

Page 68: Integration testing - A&BP CC

System Integration Testing - When?

● funded by project● sucky developers● regression● flow based applications

Page 69: Integration testing - A&BP CC

http://www.downvids.net/product-testing-institute-models-very-very-funny-hq--38051.html