effective unit testing of java ee - jbossan easymock specific mockprovider. inherits from...
TRANSCRIPT
![Page 1: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/1.jpg)
![Page 2: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/2.jpg)
Effective Unit Testing of Java EE
Heinz WilmingCarsten Erker
![Page 3: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/3.jpg)
Why do we Test?
• Confidence• Cost Reduction• Better Design• Documentation• Less Debug Time
![Page 4: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/4.jpg)
The Levels of Testing
• Unit• Integration• Acceptance• Exploratory
![Page 5: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/5.jpg)
Need(le) for Speed
• out of container testing• test components in isolation
• reduce test setup code• analyze dependencies
and provide mocks
• fast in development andexecution
![Page 6: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/6.jpg)
Basic TestNeedle JUnit Rule to instantiate
and initialize the objects under test.
Provides access to dependenciesof the the objects under test
initialized object under testinstance with injected
dependencies
![Page 7: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/7.jpg)
Needle Testcase
• Instantiation of @ O b j e c t U n d e r T e s t
Components
• Dependency Injection– Field– Method– Constuctor
• Default are Mock Objects
![Page 8: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/8.jpg)
Injection Provider
• Out of the box injection for– @ I n j e c t , @ E J B , @ R e s o u r c e ,
@ P e r s i s t e n c e C o n t e x t , @ P e r s i s t e n c e U n i t
• Configuration of additional Annotations– e.g. Seam 2 injection
• Configuration of addtional injection provider– e.g. j a v a x . i n j e c t . Q u a l i fi e r
![Page 9: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/9.jpg)
Custom Injection Provider
![Page 10: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/10.jpg)
Custom Injection Provider
1. NeedleRule
2. needle.propertiesc u s t o m . i n j e c t i o n . a n n o t a t i o n s = o r g . j b o s s . s e a m . a n n o t a t i o n s . I n ,
o r g . j b o s s . s e a m . a n n o t a t i o n s . L o g g e r
c u s t o m . i n j e c t i o n . p r o v i d e r . c l a s s e s = d e . a k q u i n e t . j u d c o n . C u r r e n t
U s e r I n j e c t i o n P r o v i d e r
![Page 11: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/11.jpg)
Testing an Object Graph
• Provide own objects• Wiring complex object graph
@ I n j e c t I n t o
@ I n j e c t I n t o M a n y
<ObjectUnderTest>UserDao
UserDaoSercuri tyLogging
<ObjectUnderTest>Authenticator
<ObjectUnderTest>S ecurit y
<Mock><Mock>
![Page 12: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/12.jpg)
Testing an Object Graph
<ObjectUnderTest>UserDao
UserDaoSercuri tyLogging
<ObjectUnderTest>Authenticator
<ObjectUnderTest>S ecurit y
<Mock><Mock>
![Page 13: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/13.jpg)
Mock Objects An EasyMock specific
MockProvider.Inherits from EasyMockSupport.
Access to injectingdependencies with the key
of the injection provider.
![Page 14: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/14.jpg)
Database Testing
• via JPA Provider, e.g. EclipseLink orHibernate
• EntityManager creation and injection• Transaction Utilities
• Optional: Execute Database operationon test setup and teardown– Import SQL Scripts– Deleting test data after the test execution
![Page 15: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/15.jpg)
Provides access to thedatabase via JPA.
Execute DB Operations
Injection Provider ofthe EntityManger
Creates andpersists an user
object
![Page 16: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/16.jpg)
Summary
• Fast• Less Glue Code• Keep Dependencies Private• Extensible• Developer Happiness ;-)
![Page 17: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/17.jpg)
Q&A
![Page 18: Effective Unit Testing of Java EE - JBossAn EasyMock specific MockProvider. Inherits from EasyMockSupport. Access to injecting dependencies with the key of the injection provider](https://reader030.vdocument.in/reader030/viewer/2022041021/5ed073cd8a07b308ce4ac7cf/html5/thumbnails/18.jpg)
[email protected]@akquinet.de
http://sourceforge.net/projects/jbosscc-needle/http://needle.spree.de
http://blog.akquinet.de/