adf vdd testing - oracledownload.oracle.com/otndocs/otnvdd-rea/ppt/adf_vdd_testing.pdf · th bit f...

26
Th bit f t The one bit everyone forgets: Testing your ADF application Testing your ADF application with JUnit John Stegeman Xchanging

Upload: leque

Post on 22-May-2018

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application with JUnit

John StegemanXchanging

Page 2: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

ADF EMGhttp://groups.google.com/group/adf-methodology

ADF EMG• A place to discuss best practices and

methodologies for JDeveloper ADF enterprise li tiapplications

• Founded mid-2008 by Chris Muir, now 600+ members

• Focus is Fusion Tech Stack (ADF Faces, ADF BC)

• Online forum plus sessions at major Oracle conferences (OOW, ODTUG, UKOUG,

<presenter, organisation>

(DOAG…)

Page 3: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

About me

• 12 years using JDeveloper (since v3)y g p ( )• 21 years using Oracle DB + tools• Oracle ACE Director (Fusion Middleware)• Oracle ACE Director (Fusion Middleware)

John StegemanXchanging

Page 4: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Agendag

• Testing / JUnit conceptsg p• Using JUnit with JDeveloper – a simple

exampleexample• Testing ADF applications with JUnit

Wh t t t t d h t * t* t t t• What to test and what *not* to test• Resources

John StegemanXchanging

Page 5: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

TESTING AND JUNITTESTING AND JUNITCONCEPTS

John StegemanXchanging

Page 6: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Why test?y

John StegemanXchanging

Page 7: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Some types of software testingyp g

• Unit• Integration• System• System• System Integration• Non-Functional (performance, scalability,

usability, etc.)

John StegemanXchanging

Page 8: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

The importance of early testingp y g

Cost to fix a defectTime detected

Req’ments Architecture Constr’ion System test Post-releaserelease

Time

Requirements 1× 3× 5–10× 10× 10–100×

ArchitectTime introduced

Architecture - 1× 10× 15× 25–100×

Construction - - 1× 10× 10–25×

Source: http://en.wikipedia.org/wiki/Software_testing

John StegemanXchanging

Page 9: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Early testing is important, so h d ’t d it ll?why don’t we do it well?

• It takes too much time• It takes too much time• Too much manual work• Unit testing treated as a “one-off” process• No experience with tools• Never taught how• Hard to get started• Hard to get started• Fill in your reason here: _____________

John StegemanXchanging

Page 10: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Test-Driven Development (TDD)*p ( )

* Can be challenging with ADF apps!

John StegemanXchanging

Page 11: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

What is JUnit?

• One of the so-called “xUnit” frameworks• Framework for writing and running

automated unit tests in Javaautomated unit tests in Java

• Can be part of a plan to overcome unit• Can be part of a plan to overcome unit testing challengesCan help enable TDD• Can help enable TDD

John StegemanXchanging

Page 12: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Some JUnit Terminologygy

• Test Method• Test Class• Assertion• Assertion• Test Fixture• Test Suite

John StegemanXchanging

Page 13: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

USING JUNIT WITHUSING JUNIT WITH JDEVELOPER

John StegemanXchanging

Page 14: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Demonstration

• Enabling JUnit for JDeveloperg p• TDD for a “factorial” class

John StegemanXchanging

Page 15: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Factorial specificationsp

• 0! = 1• For any positive integer N, return N! (the

product of all positive integers less than orproduct of all positive integers less than or equal to N)

• For any negative integer throw an• For any negative integer, throw an ArithmeticException

John StegemanXchanging

Page 16: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

TESTING ADF APPLICATIONSTESTING ADF APPLICATIONS

John StegemanXchanging

Page 17: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Testing ADF Applicationsg pp

• “Classic” unit tests are difficult to achieve– External dependencies (such as databases)– Code cannot easily be executed in isolationCode cannot easily be executed in isolation

(JSF, EO, VO)• This doesn’t mean you should give up!This doesn t mean you should give up!• JDeveloper Extension for BC testing –

useful for generating boilerplateuseful for generating boilerplate

John StegemanXchanging

Page 18: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Testing ADF Business C tComponents• Create AM configurations to use g

specifically for your tests• Tests will start from an AM – use theTests will start from an AM use the

extension• Difficult to directly test EOs• Difficult to directly test EOs

John StegemanXchanging

Page 19: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Testing JSF (ADF Faces) appsg ( ) pp

• Impossible (or nearly so) to unit test in the p ( y )classic sense– Lots of bits of code that don’t stand aloneots o b ts o code t at do t sta d a o e– Dependent on container (or extensive set of

“mock objects”)j )– Dynamically instantiated classes from ADF

Page Definitions– Usually require external resources (such as

databases)John StegemanXchanging

Page 20: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Testing JSF (ADF Faces) appsg ( ) pp

• Instead of unit tests, you can do , yintegration or system tests

• JUnit-compatible frameworks/tools:JUnit compatible frameworks/tools:– Selenium (create UI-level tests)

JSFUnit (can test internal JSF state as well– JSFUnit (can test internal JSF state as well –not personally tested with ADF)

• Will generally require deploying your app• Will generally require deploying your app to an application server

John StegemanXchanging

Page 21: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

WHAT TO TEST AND WHATWHAT TO TEST AND WHAT *NOT* TO TEST

John StegemanXchanging

Page 22: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

What to (and not to) test?( )

• Test code that you write (this includes y (“code that isn’t really code”)

• Don’t test code that Oracle writes except:Don t test code that Oracle writes, except:– when you implement a workaround for an

Oracle bugOracle bug– when you expect behaviour might change in

the future (release notes, etc.)( , )

John StegemanXchanging

Page 23: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Practical suggestions –ADF B i C tADF Business Components• Validation rules• Default values• Framework Extension classes (test by• Framework Extension classes (test by

checking the behaviour of classes that inherit)inherit)

• Application Module service methods• Any code that you write in EO/VO Java

classesJohn StegemanXchanging

Page 24: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Practical suggestions –ADF FADF Faces• Use Selenium to test the UI• Focus on the displayed output and

navigationnavigation• Test database interaction that you haven’t

already tested in the ADF BC testsalready tested in the ADF BC tests

John StegemanXchanging

Page 25: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Resources

• JUnit homepage: http://junit.orgp g p j g• Some basic docs:

http://junit sourceforge nethttp://junit.sourceforge.net• ADF Development Essentials (parts 5,6):

http://www oracle com/technetwork/articleshttp://www.oracle.com/technetwork/articles/adf/adf-essentials-098792.htmlEMG htt // l / / df• EMG: http://groups.google.com/group/adf-methodology

John StegemanXchanging

Page 26: ADF VDD Testing - Oracledownload.oracle.com/otndocs/OTNVDD-REA/ppt/ADF_VDD_Testing.pdf · Th bit f tThe one bit everyone forgets: Testing your ADF applicationTesting your ADF application

Thank you for listening!y g

John StegemanXchanging