Mock Based Unit Testing
Mock Based Unit Testing
Mock Based Unit Testing
Agenda/Scopes
Introduction of Mock Framework & Demo How to mock and do unit & scenario tests both
How to design the effective test cases by using this mock framework
Salient available features (mock, spy, stub, verify, any.. etc..) in mock framework How to test the complex UI parts/Complex interdependent/recursive/substantial code part with mocking Plans/Milestones for next to achieve 100% UI UNIT Test cases for the all the UI modules in SP7 Sprint 2 onwards An implementation plan for Sprint 2 (SP7) Questions/Answers/Finalization
We are using Mockito framework along with PowerMock for additional features
Benefits o Mockito makes mocking very easy. o It is extremely easy to read mock code. o Mockito works in any environment and has no external dependencies Drawbacks o Mockito has all the same limitations, which manually created mocks have. It is impossible to mock final classes or static methods.
Demo
The salient features which should be available with the mock framework
Focused testing Separation of stubbing and verification o Dont want any verification-related code before execution. Explicit language o Verification and stubbing code should be easy to discern, should distinguish from ordinary method calls / from any supporting code / assertions Simple stubbing model Only one type of mock, one way of creating mocks No framework-supporting code o No record(), replay() methods, no alien control/context objects. Slim API o So that anyone can use it efficiently and produce clean code Explicit errors o Verification errors should always point stack trace to failed interaction Clean stack trace
Mockito Features
Verifying code behaviors Stubbing the mock values Argument matchers Verifying exact number of invocations / at least x / never Stubbing void methods with exceptions Verification in order Changing default return values of unstubbed invocations Finding redundant invocations Shorthand for mocks creation - @Mock annotation Stubbing consecutive calls (iterator-style stubbing) Stubbing with callbacks doThrow()|doAnswer()|doNothing()|doReturn() family of methods for stubbing voids (mostly) Spying on real objects Capturing arguments for further assertions
Mockito Features
Real partial mocks Resetting mocks Troubleshooting & validating framework usage Aliases for behavior driven development (**New**) Serializable mocks For more advanced features - Powermock is also an advanced version of mocking framework which will give more testable features on top of current Mockito - http://blog.griddynamics.com/2010/03/mocking-with-mockito-andpowermock.html
While Mockito does not support Static method & final class, PowerMock is supporting these. PowerMock can work on top of Mockito.
Mockito Features
Real partial mocks Resetting mocks Troubleshooting & validating framework usage Aliases for behavior driven development (**New**) Serializable mocks For more advanced features - Powermock is also an advanced version of mocking framework which will give more testable features on top of current Mockito - http://blog.griddynamics.com/2010/03/mocking-with-mockito-andpowermock.html
Mocking Static Method Partial Mocking o We can use PowerMockito to partially mock a method using PowerMockito.spy
Workflow
Identify Interactions Create Mocks o Multiple level of mocks can be created and stubbed values Stub the required mock objects Invoke the mock object Verify/Validate the object call and output Assert Expectations from the Validation
TBD
10
Q/A/F
Q/A Finalization
Thank You
11
Filter
Calculations Group by Order by
Language (SAP, ISO, Locale) Client (MANDT) Amount, Quantity Unit / Currency Time / Date Semantic Description Unit / Currency Hierarchies (requires a key)
Leveled Parent Child Attribute relationships
Advanced Semantic (multi dim) Dimensions Measures Variables for client tools
SQL view ++
Scripts Curr Conv. Parameters
12
UI
Keep the paradigm of the current calc view editor and use that to model the new view
Include a Data Foundation Star join node for easier join modeling
Overview
2011 SAP AG. All rights reserved.
Node Detail
Node columns
13
UI
Analytic view in the new editor with two Multi join / Star join Node
Detail of JoinDIM
Detail of JoinDF
Data Foundation
Old
2011 SAP AG. All rights reserved.
New
14
Capabilities
All semantic modeling would be done in the output node? (Maybe also on the inner nodes) Everything that is possible in calc view or analytic view editor and more would be offered there including
Currency conversion can also be done inside Because some calculations will depend on converted measures The script node is like any other node and can be combined with other node types
15
Performance (brainstorming)
E.g. use the engine hints = deployment type (depending on the hint not all features are available)
SQL deploy as SQL view Calc view deploy as calc view OLAP deploy as OLAP view
Alternatively: Convert all view definitions into SQL and delegate the work to the SQL optimizer \\trextest\trex_test\dbaeumges\working\201201_SeoulWS_Optimizer_Semantic_Cal cEngine.pptx
16
T7 T8 T9
Join
T7
TCUS T4 T5 T3 T6 T5 T2
T9
T3
17