Lecture 20


Published on

  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Lecture 20

  1. 1. Testing and the UML 2.0 Testing Profile Based on FOKUS UML Tesing Profile and Object Oriented Testing By James Gain
  2. 2. Outline <ul><li>Introduction </li></ul><ul><li>Testing </li></ul><ul><li>Testing and UML </li></ul><ul><li>The Testing Profile </li></ul><ul><li>Its Relation to TTCN-3 </li></ul><ul><li>What it brings </li></ul>
  3. 3. Testing <ul><li>In general testing is the process of determining if an artifact meets a given specification. It is one of the four basic technical activities in the software development process. (analysis, design, implementing, testing). It is used to validate and verify products or the processes by which they are made. we must distinguish between the correct behaviour and the expected behaviour. Testing methods should incorporate accountability repeatability and traceability. </li></ul>
  4. 4. Testing <ul><li>Accountability: who performs the test </li></ul><ul><li>Repeatability: can the test be repeated, must have known inputs, outputs, expected and actual results. </li></ul><ul><li>Traceability is the ability to trace the history of each requirement from problem description through </li></ul><ul><ul><li>conceptual models and </li></ul></ul><ul><ul><li>specification models and </li></ul></ul><ul><ul><li>deployment models </li></ul></ul><ul><li>to the implementation in order to reconstruct the significant events that led to the final operational software system. In other words traceability is the ability to record information that will allow any investigation to reconstruct events, changes and reasons for change. </li></ul>
  5. 5. Verification and Validation <ul><li>T here is a distinction between verification (checking are we building product correctly) and validation (checking are we building the right product). </li></ul><ul><li>Program testing relates more to the testing the design (verification). </li></ul><ul><li>Model testing relates more to testing the specification (validation) </li></ul>
  6. 6. Types of Testing <ul><li>Usability testing tests the system is easy to use effectively, e.g. a GUI should offer good affordance, visibility and feedback. </li></ul><ul><li>Regression testing: Regression testing will typically only catch 50% of the existing anomalies </li></ul><ul><li>White box testing: Tests chosen by looking to the implementation. </li></ul><ul><li>Black box testing: Tests chosen by looking to the specification. </li></ul><ul><li>Inspection: The importance of implementing inspection processes becomes clearer when you consider the following dramatic statistics: Over 60% of software bugs occur before the code is ever written. Inspection is about 80% effective in removing anomalies. </li></ul><ul><li>Performance and Stress Test: e.g. number of users supported </li></ul>
  7. 7. Basis Paths <ul><li>A basis set is a set of linearly independent paths that can be used to construct any path through the program flow graph. </li></ul><ul><li>Path testing is testing designed to execute all or selected paths through a computer program. </li></ul><ul><li>Branch testing is testing designed to execute each outcome of each decision point in a computer program. </li></ul><ul><li>The test paths in a basis set fulfill the requirements of branch testing and also test all of the paths that could be used to construct any arbitrary path through the graph. </li></ul>The nodes in this graph are program statements and the directed edges are flow of control
  8. 8. Basis Paths <ul><li>A basis set is a set of linearly independent test paths. A path can be associated with a vector, where each element in the vector is the number of times that an edge is traversed. For example, consider a graph with 4 edges: a , b , c and d . The path ac can be represented by the vector [1 0 1 0]. Paths are combined by adding or subtracting the paths' vector representations. Each path in the basis set can not be formed as a combination of other paths in the basis set. Also, any path through the control flow graph can be formed as a combination of paths in the basis set. </li></ul>ac = [1 0 1 0] [a b c d]
  9. 9. Basis Paths The figure shows a simplified control flow graph. While a complete flow graph would not have two edges going to the same destination, this requirement has been relaxed to keep the number of paths to a manageable size for this example. A basis set for this graph is { ac, ad, bc}. The path bd can be constructed by the combination bc + ad - ac as shown in this table . The set {ac, bd} is not a basis set, because there is no way to construct the path ad. The set {ac, ad, bd} is also a basis set. Basis sets are not unique; thus a flowgraph can have more than one basis set. 1 1 0 1 d 0 1 1 0 c 1 1 1 1 b 0 1 0 0 a bc + ad - ac bc + ad bc bd Edge
  10. 10. Types of Testing <ul><li>Unit testing: The first stage of developmental testing in which units of functionality (e.g. classes) are tested in isolation. </li></ul><ul><li>Integration Testing: The second stage of developmental testing in which previously tested units are tested together as a unified whole. </li></ul><ul><li>System testing: The third stage of developmental testing in which the completed system is tested against the customers requirement. </li></ul><ul><li>Acceptance testing customer involvement. </li></ul><ul><li>V-model of testing: Links specification aspects with implementations through various test plans. Also there should be consistency verification, which checks that each deliverable is self consistence ,e.g. no contradictions in a specification. </li></ul><ul><li>Negotiated Statement Requirement ---- Acceptance testing-------- Delivered systemSystem </li></ul><ul><li>Design Specification --------- Integration testing --- System Components </li></ul><ul><li>Component Specification ----Unit testing --- Source code </li></ul>
  11. 11. Testing and xUML <ul><li>UML becomes executable when used with an action language </li></ul><ul><li>xUML models are finished when they execute their acceptance test correctly </li></ul><ul><li>xUML models are validated specifications which offer a strong contractual basis for implementation by external contractors or in-house teams </li></ul>
  12. 12. JUnit <ul><li>The running of tests, recording of results and reporting of errors is common to all tests, and JUnit provides precisely this functionality. A unit test exercises &quot;a unit&quot; of production code in isolation from the full system and checks that the results are as expected. The size of &quot;a unit&quot; to be tested depends on the size of a set of coherent functionality and in practice varies between a class and a package. JUnit supports writing unit test in Java for Java code. The purpose is to identify bugs in the code being tested prior to integrating the code into the rest of the system. The reason for identifying bugs before integration is that it is far easier (i.e. quicker and cheaper) to identify and correct problems (and demonstrate that the solution works) in isolation. Ideal for regression testing, if one needs to change existing code the fact that the unit test still passes the resulting code makes one more confident that the change doesn't break anything. And the better the unit test the more confident one can be - ideally the test should be updated to include the new functionality prior to making the change. </li></ul>
  13. 13. JUnit <ul><li>Unit tests and the production code can be developed independently against the specification. Used this way unit tests are likely to pick up misinterpretation of, or ambiguities in, the specification. </li></ul><ul><li>Unit tests also feature as part of &quot;Extreme Programming&quot; [XP]. The idea is to develop the interface, the test harness, and the implementation. (In roughly that order - although some parts of the implementation may be completed before unrelated parts of the test harness). </li></ul>
  14. 14. JUnit <ul><li>A piece of test code cannot be run in isolation, it needs to be part of a runtime environment. Also, it is desirable to automate the running of unit tests - such as periodically running all the test harnesses in the system to prove that nothing is broken. For this unit tests need to meet certain criteria: a successful test shouldn't need manual checking, a failed test should deliver adequate documentation for diagnosis. </li></ul>
  15. 15. JUnit <ul><li>JUnit tests can be organized into a hierarchy of test suites containing test cases and even other test suites. The composite behaviour of JUnit tests allows you to assemble collections of tests and automatically regression test the entire test suite in one fell swoop. You can also run the tests for any layer within the test suite hierarchy. </li></ul>
  16. 16. JUnit <ul><li>The fewer tests you write, the less stable your code becomes. Tests validate the stability of the software and instill confidence that changes haven't caused a ripple-effect through the software. The tests form the glue of the structural integrity of the software . </li></ul>
  17. 17. JUnit <ul><li>JUnit issues : Limitations: JUnit a Java only solution, little support for multi-threading, need to be adapted for specialized testing e.g. CACTUS for web development. Focuses on unit white-box testing. Unlike functional tests, which treat the system as a black box and ensure that the software works as a whole, unit tests are written to test the fundamental building blocks of the system from the inside out. On the other hand XP programmers say &quot;Here's my deliverable and the tests which validate it.&quot; </li></ul>
  18. 18. JUnit
  19. 19. JUnit
  20. 20. UML testing profile
  21. 21. UML Test Profile <ul><li>The UML Testing Profile defines a language for designing, visualizing, specifying, analyzing, constructing and documenting the artifacts of test systems. It is a test modelling language that can be used with all major object and component technologies and applied to testing systems in various application domains. The UML Testing Profile can be used stand alone for the handling of test artifacts or in an integrated manner with UML for a handling of system and test artifacts together. </li></ul>
  22. 22. UML Test Profile <ul><li>The UML testing profile specifically addresses typical testing concepts in model-based development. The testing profile supports the specification and modeling of software testing infrastructures. It follows the same fundamental principles of UML in that it provides concepts for the structural aspects of testing such as the definition of test components, test contexts and test system interfaces, and behavioral aspects of testing such as the definition of test procedures, test setup, execution and evaluation. The core UML may be used to model and describe testing functionality since test software development can be seen as any other development for functional software properties. However, as software testing is based on a number of special test-related concepts these are provided by the testing profile as extensions to UML. The concepts are mainly concepts for test architectures , test behaviors and test data . </li></ul>
  23. 23. UML Test Profile <ul><li>The executable versions of tests can be generated with mappings towards existing test execution environments based JUnit or TTCN-3 (Testing and Test Control Notation) which is a widely accepted technique for testing in the telecommunication and data communication domain. U2TP not yet directly mapped to ASL or OCL, because these a not ‘test frameworks’, although a test framework could be constructed from them. </li></ul>
  24. 24. UML Test Profile <ul><li>The UML Testing Profile extends UML with test specific concepts like test components , verdicts , defaults , etc. These concepts are grouped into concepts for test architecture, test data, test behavior and time. Being a profile , the UML testing profile seamlessly integrates into UML: it is based on the UML meta-model and reuses UML syntax. </li></ul>
  25. 25. UML Test Profile <ul><li>It has been architected with the following design principles in mind: </li></ul><ul><li>UML integration: as a real UML profile. UML profiles are defined in the UML infrastructure volume of UML 2.0. </li></ul><ul><li>Reuse and minimality: wherever possible, the UML Testing Profile makes direct use of the UML concepts and extends them and adds new concepts only where needed. Only those concepts are extended/added to UML, which have been demonstrated in the software, hardware and protocol testing area to be of central relevance to the definition of test artifacts and are not part of UML. </li></ul>
  26. 26. UML Test Profile <ul><li>Test Architecture </li></ul><ul><li>Test Behavior </li></ul><ul><li>Test Data </li></ul><ul><li>Time Concepts </li></ul><ul><li>There are mappings to existing frameworks TTCN-3 and JUnit. The UTP not yet linked to xUML (executable UML) or OCL, which can both be used for testing of models . </li></ul>
  27. 27. Test Architecture of UTP <ul><li>The test architecture is a set of concepts to specify the structural aspects of a test context covering test components, the system under test, their configuration, etc. </li></ul>
  28. 28. Test Architecture of UTP
  29. 29. Test Architecture of UTP <ul><li>SUT The system under test (SUT) is a part and is the system, subsystem, or component being tested. A SUT can consist of several objects. The SUT is exercised via its public interface operations and signals by the test components. No further information can be obtained from the SUT as it is a black-box. </li></ul>
  30. 30. Test Architecture of UTP <ul><li>Test Context A collection of test cases together with a test configuration on the basis of which the test cases are executed. </li></ul><ul><li>Test Configuration The collection of test component objects and of connections between the test component objects and to the SUT. The test configuration defines both (1) test component objects and connections when a test case is started (the initial test configuration) and (2) the maximal number of test component objects and connections during the test execution. </li></ul>
  31. 31. Test Architecture of UTP <ul><li>Test Component: A test component is a class of a test system. Test component objects realize the behavior of a test case. A test component has a set of interfaces via which it may communicate via connections with other test components or with the SUT. </li></ul>
  32. 32. Test Architecture of UTP <ul><li>Arbiter: A property of a test case or a test context to evaluate test results and to assign the overall verdict of a test case or test context respectively. There is a default arbitration algorithm based on functional, conformance testing, which generates Pass , Fail , Inconc , and Error as verdict, where these verdicts are ordered as Pass < Inconc < Fail < Error . The arbitration algorithm can be user-defined. </li></ul>
  33. 33. Test Architecture of UTP <ul><li>Scheduler: A property of a test context used to control the execution of the different test components. The scheduler will keep information about which test components exist at any point in time, and it will collaborate with the arbiter to inform it when it is time to issue the final verdict. It keeps control over the creation and destruction of test components and it knows which test components take part in each test case. </li></ul>
  34. 34. Test Architecture of UTP <ul><li>Utility Part: A part of the test system representing miscellaneous components which help test components to realize their test behavior. Examples of utility parts are miscellaneous features of the test system. </li></ul>
  35. 35. Test Behavior <ul><li>Test Behavior: The set of concepts to specify test behaviors, their objectives and the evaluation of systems under test. </li></ul><ul><li>Test Control A test control is a specification for the invocation of test cases within a test context. It is a technical specification of how the SUT should be tested with the given test context. </li></ul>
  36. 36. Test Behavior <ul><li>Test Case: A test case is a specification of one case to test the system, including what to test with which input, result, and under which conditions. It is a complete technical specification of how the SUT should be tested for a given test objective. A test case is defined in terms of sequences, alternatives, loops and defaults of stimuli to and observations from the SUT. It implements a test objective. A test case may invoke other test cases. A test case uses an arbiter to evaluate the outcome of its test behavior. A test case is a property of a test context. It is an operation specifying how a set of cooperating test components interacting with a system under test realize a test objective. Both the system under test and the different test components are parts of the test context to which the test case belongs. </li></ul>
  37. 37. Test Behavior <ul><li>Test Invocation A test case can be invoked with specific parameters and within a specific context. The test invocation leads to the execution of the test case. The test invocation is denoted in the test log. </li></ul><ul><li>Test Objective A test objective is a named element describing what should be tested. It is associated to a test case. </li></ul>
  38. 38. Test Behavior <ul><li>Stimulus Test data sent to the SUT in order to control it and to make assessments about the SUT when receiving the SUT reactions to these stimuli. </li></ul><ul><li>Observation Test data reflecting the reactions from the SUT and used to assess the SUT reactions which are typically the result of a stimulus sent to the SUT. </li></ul>
  39. 39. Test Behavior <ul><li>Coordination Concurrent (and potentially distributed) test components have to be coordinated both functionally and in time in order to assure deterministic and repeatable test executions resulting in well-defined test verdicts. Coordination is done explicitly with normal message exchange between components or implicitly with general ordering mechanisms. </li></ul><ul><li>A Default is a behavior triggered by a test observation that is not handled by the behavior of the test case per se. Defaults are executed by test components. </li></ul>
  40. 40. Test Behavior <ul><li>Verdict: Verdict is the assessment of the correctness of the SUT. Test cases yield verdicts. Verdicts can also be used to report failures in the test system. Predefined verdict values are pass , fail , inconclusive and error . Pass indicates that the test behavior gives evidence for correctness of the SUT for that specific test case. Fail describes that the purpose of the test case has been violated. Inconclusive is used for cases where neither a Pass nor a Fail can be given. An Error verdict shall be used to indicate errors (exceptions) within the test system itself. Verdicts can be user-defined. The verdict of a test case is calculated by the arbiter. </li></ul>
  41. 41. Test Behavior <ul><li>Validation Action: An action to evaluate the status of the execution of a test case by assessing the SUT observations and/or additional characteristics/parameters of the SUT. A validation action is performed by a test component and sets the local verdict of that test component. </li></ul><ul><li>Log Action: An action to log information in the test log. </li></ul><ul><li>Test Log: A log is an interaction resulting from the execution of a test case. It represents the different messages exchanged between the test components and the SUT and/or the states of the involved test components. A log is associated with a verdict representing the adherence of the SUT to the test objective of the associated test case. </li></ul>
  42. 42. Test Data <ul><li>Test Data: The set of concepts to specify data used in stimuli to the SUT, observations from the SUT and for coordination between test components. </li></ul><ul><li>Wildcard: Wildcards allow the user to explicitly specify whether the value is present or not, and/or whether it is of any value. Wildcards are special symbols to represent values or ranges of values. Wildcards are used instead of symbols within instance specifications. Three wildcards exist: a wildcard for any value, a wildcard for any value or no value at all (i.e. an omitted value) and a wildcard for an omitted value. </li></ul>
  43. 43. Test Data <ul><li>Data Pool A data pool is a collection of data partitions or explicit values that are used by a test context, or test components, during the evaluation of test contexts and test cases. In doing so, a data pool provides a means for providing values or data partitions for repeated tests. </li></ul><ul><li>Data Partition A logical value for a parameter used in a stimulus or in an observation. It typically defines an equivalence class for a set of values, e.g. valid user names etc,. </li></ul><ul><li>Data Selector An operation that defines how data values or equivalence classes are selected from a data pool or data partition. </li></ul><ul><li>Coding Rule The interfaces of a SUT use certain encodings (e.g. CORBA GIOP/IIOP, IDL, ASN.1 PER or XML), which have to be respected by the test systems. Hence, coding rules are part of a test specification. </li></ul>
  44. 44. Time Concepts <ul><li>The set of concepts to specify time constraints, time observations and/or timers within test behavior specifications in order to have a time quantified test execution and/or the observation of the timed execution of test cases. </li></ul><ul><li>Timezone: Timezone is a grouping mechanism for test components. Each test component belongs to a certain timezone. Test components in the same timezone have the same time, i.e. test components of the same timezone are time synchronized. </li></ul>
  45. 45. Time Concepts <ul><li>Timer Timers are mechanisms that may generate a timeout event when a specified time value occurs. This may be when a pre-specified time interval has expired relative to a given instant (usually the instant when the timer is started). Timers belong to test components. They are defined as properties of test components. A timer is started with an expiration time being the time when the timeout is to be issued. A timeout indicates the timer expiration. A timer can be stopped. The expiration time of a running timer and its current status (e.g. active/inactive) can be checked. </li></ul>
  46. 46. UML Test Profile and JUnit <ul><li>There is a mapping from the UML Testing Profile to JUnit. This mapping considers primarily the JUnit framework: When no trivial mapping exists to the JUnit framework, existing extensions to the framework are used as examples of how the framework has been extended to support some of the concepts included in the UML Testing Profile. </li></ul>
  47. 47. UML Test Profile to JUnit Mappings <ul><li>Verdict In JUnit, predefined verdict values are pass , fail , and error . Pass indicates that the test behavior gives evidence for correctness of the SUT for that specific Test Case. Fail describes that the purpose of the Test Case has been violated. An Error verdict shall be used to indicate errors (exceptions) within the test system itself. </li></ul><ul><li>There is no such thing as an Inconclusive verdict in JUnit. Therefore, the Inconclusive verdict will be generally mapped into Fail . </li></ul>
  48. 48. UML Test Profile to JUnit Mappings <ul><li>Test Context : A test context is realized in JUnit as a class inheriting from the JUnit TestCase class. To be noticed that the concept of Test Context exists in the JUnit framework but is different from the one defined in the UML Testing Profile. </li></ul>
  49. 49. UML Test Profile to JUnit Mappings <ul><li>Arbiter : The arbiter can be realized as a property of Test Context of a type TestResult. There is a default arbitration algorithm which generates Pass , Fail , and Error as verdict, where these verdicts are ordered as Pass < Fail < Error . The arbitration algorithm can be user-defined. </li></ul>
  50. 50. UML Test Profile to JUnit TTCN-3 <ul><li>TTCN-3 - Testing and Test Control Notation is widely accepted as a standard for test system development in the telecommunication and data communication area. TTCN-3 comprises concepts suitable to all types of distributed system testing. TTCN-3 test specification consists of four main parts: </li></ul><ul><ul><li>type definitions for test data structures </li></ul></ul><ul><ul><li>templates definitions for concrete test data </li></ul></ul><ul><ul><li>function and test case definitions for test behavior </li></ul></ul><ul><ul><li>control definitions for the execution of test cases </li></ul></ul>
  51. 51. Introduction SWIFTNet SWIFTBureau US Bank SSSB Client Clearing Company OTC Market Makers EU Bank SSSB Client EU Bank Network US Bank Network SWIFTBureau System-integration level tests Unit-level tests System-level tests
  52. 52. Introduction Developer Heterogeneity increases Testing throughout the process Integrator Systems Integrator
  53. 53. Introduction: Extreme View Testing tight to Specification e.g. OCL,iUML, TTCN-3 Testing tight to Development e.g. JUnit Developer Integrator Systems Integrator
  54. 54. Introduction: Balanced View Testing tight to Services e.g. OCL,iUML, TTCN-3 Testing tight to Development e.g. JUnit Developer Integrator Systems Integrator
  55. 55. An Answer: Model-Based View use case diagrams class diagrams state machines interactions Developer Integrator Systems Integrator Testing tight to Specification e.g. OCL,iUML, TTCN-3 Testing tight to Development e.g. JUnit
  56. 56. UML and Testing <ul><li>UML-based test generation </li></ul><ul><li>UML-based test notation </li></ul><ul><ul><li>Agedis, EC IST project </li></ul></ul><ul><ul><li>UML Testing Profile, OMG </li></ul></ul>
  57. 57. The Testing Profile Roots UML Testing Profile <ul><li>Test control </li></ul><ul><li>Wildcards </li></ul><ul><li>Defaults </li></ul><ul><li>Test components </li></ul><ul><li>Arbiter </li></ul><ul><li>Validation actions </li></ul><ul><li>Data pools </li></ul>Protocol Testing like TTCN-3 Software Testing like JUnit, TET, etc. MSC-2000 UML 1.x SDL-2000 MSC-2000 UML 2.0 Graphical Format of TTCN-3
  58. 58. Concepts of the Testing Profile <ul><li>Test architecture </li></ul><ul><ul><li>Test structure, test components and test configuration </li></ul></ul><ul><li>Test data </li></ul><ul><ul><li>Test data and templates used in test procedures </li></ul></ul><ul><li>Test behavior </li></ul><ul><ul><li>Dynamic aspects of test procedures </li></ul></ul><ul><li>Test time </li></ul><ul><ul><li>Time quantified definition of test procedures </li></ul></ul>
  59. 59. Concepts beyond TTCN-3 <ul><li>Unification of test cases: </li></ul><ul><ul><li>Test case as a composition of test cases </li></ul></ul><ul><ul><li>Test behavior defines the execution of a test case </li></ul></ul><ul><li>Separation of test behavior and verdict handling </li></ul><ul><ul><li>Arbiter is a special component to evaluate the verdict </li></ul></ul><ul><ul><li>Validation actions are used to set the verdict </li></ul></ul><ul><li>Abstract test cases which can use a set of stimulus data </li></ul><ul><ul><li>Data partitions to describe value ranges for observations and stimuli </li></ul></ul><ul><li>Test architecture with test deployment support </li></ul><ul><ul><li>Part of the test specification is the definition of deployment requirements for a test case </li></ul></ul>
  60. 60. Concepts beyond UML <ul><li>Defaults within test behavior </li></ul><ul><ul><li>Concentration on main flow of test behavior </li></ul></ul><ul><ul><li>Default hierarchy to handle different concerns </li></ul></ul><ul><li>Wildcards within test data </li></ul><ul><ul><li>Flexible definition of value sets </li></ul></ul><ul><li>Timers and time constraints </li></ul><ul><ul><li>Time controlled test behavior </li></ul></ul><ul><li>Arbitration and verdicts </li></ul><ul><ul><li>Assessment of test behavior </li></ul></ul>
  61. 61. An Example System Test ATM HWControl Bank « import » « import » Money « import » SWIFTNetwork « import » « import »
  62. 62. System Level Test Test suite with test cases Test component Miscellaneous „ Test package“ ATM « import » ATMTest « testSuite » ATMSuite - verdict : Verdict - amount : IMoney - targetBank : SwiftId - targetAccount : String - sourceAccount : String « testCase » +validWiring() : Verdict « testCase » +invalidPIN() : Verdict « testCase » - authorizeCard() : Verdict * - accounts « t estComponent » BankEmulator IBank « interface » IAccount - pinOk : Boolean - enteredPIN : String - message : String - t1 : Timer « testComponent » HWEmulator hwCom IATM IHardware
  63. 63. Test Configuration current : CardData Utility property SUT propery Test component property Coding rules Connections be : BankEmulator hwe : HWEmulator atmPort « sut » atm : BankATM bankCom « testSuite » class ATMSuite coding ” Encrypted” « testSuite » ATMSuite - verdict : Verdict - amount : IMoney - targetBank : SwiftId - targetAccount : String - sourceAccount : String « testCase » +validWiring() : Verdict « testCase » +invalidPIN() : Verdict « testCase » - authorizeCard() : Verdict
  64. 64. Test Control (Execution of Test Suite) Referring test case behaviors sd ATMSuite [verdict == fail] [verdict == pass] verdict = invalidPIN ref verdict = validWiring ref « testSuite » ATMSuite - verdict : Verdict - amount : IMoney - targetBank : SwiftId - targetAccount : String - sourceAccount : String « testCase » +validWiring() : Verdict « testCase » +invalidPIN() : Verdict « testCase » - authorizeCard() : Verdict
  65. 65. A Test Case « validationAction » pass {readOnly} Integer invalidPIN; { current.isPinCorrect(invalidPIN) == false } Data partition Arbitrated verdict Timing SUT and Test Component Lifelines sd invalidPIN hwe « sut » atm storeCardData(current) display(”Enter PIN”) isPinCorrect( invalidPIN) current isPinCorrect( invalidPIN ) display(”Invalid PIN”) display(”Enter PIN again”) isPinCorrect : false isPinCorrect : false t1(2.0) t1 {0 .. 3}
  66. 66. A Test Case with Default (Extract) Default application default DisplayDefault default DisplayDefault
  67. 67. Defaults Defining an event-specific default Applying a component-specific default Defining a component-specific default
  68. 68. The Mappings <ul><li>To enable the direct execution of U2TP specifications by reusing existing test infrastructures </li></ul><ul><li>Mappings to </li></ul><ul><ul><li>The JUnit test framework </li></ul></ul><ul><ul><ul><li>An open source test technology for Java </li></ul></ul></ul><ul><ul><ul><li>Black-box tests on unit level </li></ul></ul></ul><ul><ul><ul><li>Only selected aspects of U2TP can be mapped </li></ul></ul></ul><ul><ul><li>The Testing and Test Control Notation TTCN-3 </li></ul></ul><ul><ul><ul><li>A generic test technology by ETSI/ITU-T </li></ul></ul></ul><ul><ul><ul><li>Black-box/grey-box tests on unit, component, integration and system level </li></ul></ul></ul><ul><ul><ul><li>Almost all concepts can be mapped </li></ul></ul></ul>
  69. 69. Example for Mapping to TTCN-3 ... type port hwCom_PType procedure {...} ... type component HWEmulator_CType{ port atmPort_PType hwCom; var boolean pinOk; var charstring enteredPIN; var charstring message_; timer t1; } ATMTest - pinOk : Boolean - enteredPIN : String - message : String - t1 : Timer « testComponent » HWEmulator hwCom IATM IHardware
  70. 70. Example for Mapping to TTCN-3 sd invalidPIN storeCardData(current) « sut » atm hwe display( ” Enter PIN ” ) isPinCorrect( invalidPIN) isPinCorrect : false « validationAction » pass current {readOnly} Integer invalidPIN; { current.isPinCorrect(invalidPIN ) == false } isPinCorrect( invalidPIN ) display( ” Invalid PIN ” ) display( ” Enter PIN again ” ) isPinCorrect : false t1(2.0) t1 {0 .. 3} function invalidPIN_hwe ... { ... hwCom.call( storeCardData:{current},nowait); t1.start(2.0); hwCom.getreply( display_:{&quot;Enter PIN&quot;}); t1.stop; hwCom.call( isPinCorrect:{invalidPIN},3.0) { [] hwCom.getreply( isPinCorrect:{?} value false) {} } hwCom.getreply( display_:{&quot;Invalid PIN&quot;}); hwCom.getreply( display_:{&quot;Enter PIN again&quot;}); setverdict(pass); }
  71. 71. At the End: a Standardized Testing Profile <ul><li>One test notation for many testing applications </li></ul><ul><li>Universally understood syntax and operational semantics </li></ul><ul><li>Off-the-shelf tools </li></ul><ul><li>Cheaper education and training costs </li></ul><ul><li>Exchange and reuse of test suites </li></ul><ul><li>Easier maintenance of test suites </li></ul><ul><li>Transparency for the test process, increase of the objectiveness of tests and comparability of test results </li></ul><ul><li>Direct support for test design </li></ul><ul><li>Integration in the system development process </li></ul>
  72. 72. Developed by <ul><li>Submitters </li></ul><ul><ul><li>Ericsson </li></ul></ul><ul><ul><li>IBM </li></ul></ul><ul><ul><li>FOKUS </li></ul></ul><ul><ul><li>Motorola </li></ul></ul><ul><ul><li>Rational </li></ul></ul><ul><ul><li>Softeam </li></ul></ul><ul><ul><li>Telelogic </li></ul></ul><ul><ul><li>University of Lübeck </li></ul></ul><ul><li>Supporters </li></ul><ul><ul><li>iLogix </li></ul></ul><ul><ul><li>ScapaTechnologies </li></ul></ul><ul><ul><li>IRISA </li></ul></ul><ul><li>A consortium of testers , UML vendors and users dedicated to make UML applicable for software testing </li></ul>
  73. 73. Implementations under Development <ul><li>Eclipse Project Hyades on an Open Source Trace and Test Framework </li></ul><ul><ul><li>The test part is based on the U2TP specification </li></ul></ul><ul><li>Microsoft Visual Studio </li></ul><ul><li>ITEA Project on Advanced Test Methods and Tools TTmedal </li></ul>
  74. 74. Summary of Testing Profile <ul><li>UML Testing Profile provides specification means for test artifacts of systems from various domains </li></ul><ul><li>Enhances UML with concepts like test configuration, test components, SUT, verdict and default </li></ul><ul><li>Seamlessly integrates into UML: being based on UML metamodel, using UML syntax </li></ul><ul><li>Direct support for test design </li></ul><ul><li>Integration with the system development process </li></ul>
  75. 75. Summary of Testing (slides 1-71) <ul><li>Testing is the process of determining if an artefact meets a given specification. It is one of the four basic technical activities in the software development process. (analysis, design, implementing testing). It is used to validate and verify products or the processes by which they are made. we must distinguish between the correct behaviour and the expected behaviour . Testing methods should incorporate accountability repeatability and traceability . </li></ul><ul><li>Many approaches to testing (slides 6-7). </li></ul>
  76. 76. Testing Objectives <ul><li>Many strategies and tools associated with object oriented testing </li></ul><ul><ul><li>Analysis and Design Testing </li></ul></ul><ul><ul><li>Class Tests </li></ul></ul><ul><ul><li>Integration Tests </li></ul></ul><ul><ul><li>System Tests </li></ul></ul><ul><ul><li>Validation Tests </li></ul></ul>analysis design code test
  77. 77. A Broader View of Testing <ul><li>Nature of OO systems influence both testing strategy and methods </li></ul><ul><li>Will re-use mean less need for testing? NO </li></ul><ul><li>In Object Oriented systems the view of testing is broadened to encompass Analysis and Design </li></ul><ul><li>“ It can be argued that the review of OO analysis and design models is especially useful because the same semantic constructs (e.g., classes, attributes, operations, messages) appear at the analysis, design, and code level.” </li></ul><ul><li>Allows early circumvention of later problems </li></ul>
  78. 78. Object-Oriented Testing <ul><li>Analysis and Design: </li></ul><ul><ul><li>Testing begins by evaluating the OOA and OOD models </li></ul></ul><ul><ul><li>Cannot be executed, so conventional testing impossible </li></ul></ul><ul><ul><li>Use formal technical reviews of correctness, completeness and consistency </li></ul></ul><ul><li>Programming: </li></ul><ul><ul><li>OO Code testing differs from conventional methods: </li></ul></ul><ul><ul><ul><li>The concept of the ‘unit’ broadens due to class encapsulation </li></ul></ul></ul><ul><ul><ul><li>Integration focuses on classes and their execution across a ‘thread’ or in the context of a usage scenario </li></ul></ul></ul><ul><ul><ul><li>Validation uses conventional black box methods </li></ul></ul></ul><ul><ul><li>Test case design draws on conventional methods, but also encompasses special features </li></ul></ul>
  79. 79. Criteria for Completion of Testing <ul><li>When are we done testing? </li></ul><ul><li>Testing is never done, the burden simply shifts from you to the customer </li></ul><ul><li>Testing is done when you run out of time or money </li></ul><ul><li>Statistical Model: </li></ul><ul><ul><li>Assume that errors decay logarithmically with testing time </li></ul></ul><ul><ul><li>Measure the number of errors in a unit period </li></ul></ul><ul><ul><li>Fit these measurements to a logarithmic curve </li></ul></ul><ul><ul><li>Can then say: “with our experimentally valid statistical model we have done sufficient testing to say that with 95% confidence the probability of 1000 CPU hours of failure free operation is at least 0.995” </li></ul></ul><ul><li>More research needs to be done into how to answer this question </li></ul>
  80. 80. Strategic Issues <ul><li>Issues to address for a successful software testing strategy: </li></ul><ul><ul><li>Specify product requirements in a quantifiable manner long before testing commences. For example, portability, maintainability, usability </li></ul></ul><ul><ul><li>State testing objectives explicitly. For example, mean time to failure, test coverage, etc </li></ul></ul><ul><ul><li>Understand the users of the software and develop a profile for each user category. Use cases do this </li></ul></ul><ul><ul><li>Develop a testing plan that emphasizes “rapid cycle testing”. Get quick feedback from a series of small incremental tests </li></ul></ul><ul><ul><li>Build robust software that is designed to test itself. Exception handling and automated testing </li></ul></ul><ul><ul><li>Conduct formal technical reviews to assess the test strategy and test cases themselves. “Who watches the watchers” </li></ul></ul><ul><ul><li>Develop a continuous improvement approach to the testing process </li></ul></ul>
  81. 81. Testing Analysis and Design <ul><li>Syntactic correctness: </li></ul><ul><ul><li>Is UML notation used correctly? </li></ul></ul><ul><li>Semantic correctness: </li></ul><ul><ul><li>Does the model reflect the real world problem? </li></ul></ul><ul><ul><li>Is UML used as intended by its designers? </li></ul></ul><ul><li>Testing for consistency: </li></ul><ul><ul><li>Are different views of the system in agreement? </li></ul></ul><ul><ul><li>An inconsistent model has representations in one part that are not correctly reflected in other portions of the model </li></ul></ul>
  82. 82. Testing the Class Model <ul><li>Revisit the CRC model and the class model. Check that all collaborations are properly represented in both </li></ul><ul><li>Inspect the description of each CRC index card to determine if a delegated responsibility is part of the collaborator’s definition </li></ul><ul><ul><li>Example: in a point of sale system. A read credit card responsibility of a credit sale class is accomplished if satisfied by a credit card collaborator </li></ul></ul><ul><li>Invert the connection to ensure that each collaborator that is asked for a service is receiving requests from a reasonable source </li></ul><ul><ul><li>Example: a credit card being asked for a purchase amount (a problem) </li></ul></ul>
  83. 83. Final Steps in Testing the Class Model <ul><li>Using the inverted connections examined in step 3, determine whether other classes might be required or whether responsibilities are properly grouped among the classes </li></ul><ul><li>Determine whether widely requested responsibilities might be combined into a single responsibility </li></ul><ul><ul><li>Example: read credit card and get authorization could easily be grouped into validate credit request </li></ul></ul><ul><li>Steps 1 to 5 are applied iteratively and repeatedly </li></ul>
  84. 84. Testing OO Code class tests integration tests validation tests system tests
  85. 85. [1] Class Testing <ul><li>Smallest testable unit is the encapsulated class </li></ul><ul><li>A single operation needs to be tested as part of a class hierarchy because its context of use may differ subtly </li></ul><ul><li>Class testing is the equivalent of unit testing in conventional software </li></ul><ul><li>Approach: </li></ul><ul><ul><li>Methods within the class are tested </li></ul></ul><ul><ul><li>The state behavior of the class is examined </li></ul></ul><ul><li>Unlike conventional unit testing which focuses on input-process-output, class testing focuses on designing sequences of methods to exercise the states of a class </li></ul><ul><li>But white-box methods can still be applied </li></ul>
  86. 86. Class Test Case Design <ul><li>Each test case should be uniquely identified and should be explicitly associated with the class to be tested </li></ul><ul><li>The purpose of the test should be stated </li></ul><ul><li>A list of testing steps should be developed for each test and should contain: </li></ul><ul><ul><li>A list of specified states for the object that is to be tested </li></ul></ul><ul><ul><li>A list of messages and operations that will be exercised as a consequence of the test </li></ul></ul><ul><ul><li>A list of exceptions that may occur as the object is tested </li></ul></ul><ul><ul><li>A list of external conditions (i.e., changes in the environment external to the software that must exist in order to properly conduct the test) </li></ul></ul><ul><ul><li>Supplementary information that will aid in understanding or implementing the test </li></ul></ul>
  87. 87. Challenges of Class Testing <ul><li>Class: </li></ul><ul><ul><li>A class should be the basic unit for testing, this is harder to test than a function. In general the OO testing space is much greater. Objects must be tested in all their possible states, every transition of a state diagram should be tested. We are concerned about the receiver, sender and to some extent the arguments of messages. Flow of control path analysis is more difficult in OO there may be many possible paths depending on the class of the receiver, sender or </li></ul></ul>
  88. 88. Challenges of Class Testing <ul><li>For a particular class, unit testing should consist of five parts: </li></ul><ul><li>• interface testing, in which test data is chosen to check that the flow of information into and out from an object of the class is correct; </li></ul><ul><li>• boundary-condition testing, in which test data are chosen to check that methods perform correctly at the extremities of input ranges; </li></ul><ul><li>• local-data testing, in which test data are chosen to check that methods manipulate attributes correctly, so that an object’s state remains consistent; </li></ul><ul><li>• control-structure testing, in which test data are chosen to check that algorithms are coded correctly and to execute each statement in the code at least once; </li></ul><ul><li>• error-handler testing, in which test data are chosen to check that the object performs correctly in exceptional situations. </li></ul>
  89. 89. Challenges of Class Testing <ul><li>Encapsulation: </li></ul><ul><ul><li>Encapsulation is the hiding from clients of a class the details of how the class is implemented. So the tester may not have access to the state of the object. This is fine for black box testing, but not for white box testing. Difficult to obtain a snapshot of a class without building extra methods which display the classes’ state. This could be made a little easier by using a tool like JUnit </li></ul></ul><ul><li>White box tests: </li></ul><ul><ul><li>Basis path, condition, data flow and loop tests can all be applied to individual methods within a class but they don’t test interactions between methods </li></ul></ul>
  90. 90. Challenges of Class Testing <ul><li>Inheritance: </li></ul><ul><li>Inherited functionality must be tested in the new subclass. In defining a subclass we have changed the context in which messages in the superclass may be executed particularly in the new subclass. Because of dynamic binding methods non overridden as well as those overridden methods must be tested. When an object of class A interacts with an object of class B, it may in fact be interacting with an object of any subclass , which may not have been written when class A was written and tested. Abstract classes, were never intended to be executed so can only be tested with extra specially test code. In OO languages a test harness can be used that allows the programmer to subclass the supplied testing classes in the test harness to allow application specific test classes. This means the testing does not interfere with the code of the SUT. </li></ul><ul><li>In summary, each new context of use (subclass) requires re-testing because a method may be implemented differently (polymorphism). Other unaltered methods within the subclass may use the redefined method and need to be tested </li></ul>
  91. 91. Challenges of Class Testing <ul><li>Polymorphism </li></ul><ul><li>Polymorphism is the ability of objects to send the same message to instances of different classes which do not have necessarily have a common superclass i.e. polymorphism without inheritance. It is possible the methods are defined differently in sub-hierarchies i.e. the subclass methods do not share the same super class definition. It is necessary to test class hierarchies for different implementations of the method. </li></ul><ul><li>A method may use a collection as an argument which could be a set, bag, sorted collection, ordered collection. These heterogeneous collections may have an impact affect the methods behaviour, the method may encounter a collection type that it cannot handle. </li></ul>
  92. 92. Challenges of Integration Testing <ul><li>Consider a base class, PlaneFigure, from which the classes Triangle, Circle and Line are all derived. </li></ul><ul><li>We might define an abstract method draw in PlaneFigure to indicate that derived classes should be able to render themselves to the screen. Triangle, Circle and Line will implement draw as they wish. </li></ul><ul><li>Furthermore, suppose classes A, B and C have a </li></ul><ul><li>design (PlaneFigure aFigure) method which invokes aFigure.draw. </li></ul>
  93. 93. Challenges of Integration Testing <ul><li>The dynamic binding of the draw method means that, at run time, any of three different draw methods could be invoked (one for each of Triangle, Circle and Line) for each of the classes A, B and C, so that nine possible run-time combinations exist. This is illustrated in Figure 2.2. </li></ul>
  94. 94. Challenges of Integration Testing An arrow represents invocation; the arrow between class A and aFigure.draw means that aFigure.draw is invoked from within a method of A, perhaps indirectly. Similarly, aTriangle.draw is invoked from aFigure.draw .
  95. 95. Challenges of Integration Testing <ul><li>Should we test all of them? Conceivably, errors in the Triangle draw method could be uncovered only when the calling object is an object of class C, but not when called by A or B. In this case, it is only by testing the combination of C with Triangle that we could discover the error. When errors are dependent in this way, the best testing strategy is to test all combinations; in this simple case, we could test all nine combinations and so be sure of testing the erroneous combination. This is theoretically the only strategy for ensuring that all combinations of invoking and target classes are tested together, and so of being sure of testing dependent errors. </li></ul>
  96. 96. Challenges of Integration Testing
  97. 97. Random Class Testing <ul><li>Identify methods applicable to a class </li></ul><ul><li>Define constraints on their use – e.g. the class must always be initialized first </li></ul><ul><li>Identify a minimum test sequence – an operation sequence that defines the minimum life history of the class </li></ul><ul><li>Generate a variety of random (but valid) test sequences – this exercises more complex class instance life histories </li></ul>
  98. 98. Random Class Testing <ul><li>Example: </li></ul><ul><ul><li>An account class in a banking application has open , setup , deposit , withdraw , balance , summarize and close methods </li></ul></ul><ul><ul><li>The account must be opened first and closed on completion </li></ul></ul><ul><ul><li>Open – setup – deposit – withdraw – close </li></ul></ul><ul><ul><li>Open – setup – deposit –* [deposit | withdraw | balance | summarize] – withdraw – close . Generate random test sequences using this template </li></ul></ul>
  99. 99. Partition Class Testing <ul><li>Reduces the number of test cases required (similar to equivalence partitioning) </li></ul><ul><li>State-based partitioning </li></ul><ul><ul><li>Categorize and test methods separately based on their ability to change the state of a class </li></ul></ul><ul><ul><li>Example: deposit and withdraw change state but balance does not </li></ul></ul><ul><li>Attribute-based partitioning </li></ul><ul><ul><li>Categorize and test operations based on the attributes that they use </li></ul></ul><ul><ul><li>Example: attributes balance and creditLimit can define partitions </li></ul></ul><ul><li>Category-based partitioning </li></ul><ul><ul><li>Categorize and test operations based on the generic function each performs </li></ul></ul><ul><ul><li>Example: initialization ( open , setup ), computation ( deposit , withdraw ), queries ( balance , summarize ), termination ( close ) </li></ul></ul>
  100. 100. [2] Integration Testing <ul><li>OO does not have a hierarchical control structure so conventional top-down and bottom-up integration tests have little meaning </li></ul><ul><li>Integration applied three different incremental strategies </li></ul><ul><ul><li>Thread-based testing: integrates classes required to respond to one input or event </li></ul></ul><ul><ul><li>Use-based testing: integrates classes required by one use case </li></ul></ul><ul><ul><li>Cluster testing: integrates classes required to demonstrate one collaboration </li></ul></ul>
  101. 101. Random Integration Testing <ul><li>Multiple Class Random Testing </li></ul><ul><ul><li>For each client class, use the list of class methods to generate a series of random test sequences. The methods will send messages to other server classes </li></ul></ul><ul><ul><li>For each message that is generated, determine the collaborating class and the corresponding method in the server object </li></ul></ul><ul><ul><li>For each method in the server object (that has been invoked by messages sent from the client object), determine the messages that it transmits </li></ul></ul><ul><ul><li>For each of the messages, determine the next level of methods that are invoked and incorporate these into the test sequence </li></ul></ul>
  102. 102. Behavioral Integration Testing <ul><li>Derive tests from the object-behavioural analysis model </li></ul><ul><li>Each state in a State diagram should be visited in a “breadth-first” fashion. </li></ul><ul><ul><li>Each test case should exercise a single transition </li></ul></ul><ul><ul><li>When a new transition is being tested only previously tested transitions are used </li></ul></ul><ul><ul><li>Each test case is designed around causing a specific transition </li></ul></ul><ul><li>Example: </li></ul><ul><ul><li>A credit card can move between undefined , defined , submitted and approved states </li></ul></ul><ul><ul><li>The first test case must test the transition out of the start state undefined and not any of the other later transitions </li></ul></ul>
  103. 103. [3] Validation Testing <ul><li>Are we building the right product? Validation succeeds when software functions in a manner that can be reasonably expected by the customer. </li></ul><ul><li>Focus on user-visible actions and user-recognizable outputs </li></ul><ul><li>Details of class connections disappear at this level and the focus moves to: </li></ul><ul><ul><li>Use-case scenarios from the software requirements spec </li></ul></ul><ul><ul><li>Black-box testing to create a deficiency list </li></ul></ul><ul><ul><li>Acceptance tests through alpha (at developer’s site) and beta (at customer’s site) testing with actual customers </li></ul></ul>
  104. 104. [4] System Testing <ul><li>Software may be part of a larger system. This often leads to “finger pointing” by other system dev teams </li></ul><ul><li>Finger pointing defence: </li></ul><ul><ul><li>Design error-handling paths that test external information </li></ul></ul><ul><ul><li>Conduct a series of tests that simulate bad data </li></ul></ul><ul><ul><li>Record the results of tests to use as evidence </li></ul></ul><ul><li>Types of System Testing: </li></ul><ul><ul><li>Recovery testing: how well and quickly does the system recover from faults </li></ul></ul><ul><ul><li>Security testing: verify that protection mechanisms built into the system will protect from unauthorized access (hackers, disgruntled employees, fraudsters) </li></ul></ul><ul><ul><li>Stress testing: place abnormal load on the system </li></ul></ul><ul><ul><li>Performance testing: investigate the run-time performance within the context of an integrated system </li></ul></ul>
  105. 105. [4] System Testing <ul><li>Types of System Testing: </li></ul><ul><ul><li>Recovery testing: how well and quickly does the system recover from faults </li></ul></ul><ul><ul><li>Security testing: verify that protection mechanisms built into the system will protect from unauthorized access (hackers, disgruntled employees, fraudsters) </li></ul></ul><ul><ul><li>Stress testing: place abnormal load on the system </li></ul></ul><ul><ul><li>Performance testing: investigate the run-time performance within the context of an integrated system </li></ul></ul>
  106. 106. Automated Testing <ul><li>CPPUnit on SourceForge.net </li></ul><ul><li>Differentiates between: </li></ul><ul><ul><li>Errors (unanticipated problems usually caught by exceptions) </li></ul></ul><ul><ul><li>Failures (anticipated problems checked for with assertions) </li></ul></ul><ul><li>Basic unit of testing: </li></ul><ul><ul><li>CPPUNIT_ASSERT(Bool) examines an expression </li></ul></ul><ul><li>CPPUnit has a variety of test classes (e.g. TestFixture ). Approach is to inherit from them and overload particular methods </li></ul>
  107. 107. Testing Summary <ul><li>Testing is integrated with and affects all stages of the Software Engineering lifecycle </li></ul><ul><li>Strategies: a bottom-up approach – class, integration, validation and system level testing </li></ul><ul><li>Techniques: </li></ul><ul><ul><li>white box (look into technical internal details) </li></ul></ul><ul><ul><li>black box (view the external behaviour) </li></ul></ul><ul><ul><li>debugging (a systematic cause elimination approach is best) </li></ul></ul>analysis design code test
  108. 108. Testing Summary <ul><li>Verification is the process of checking that each system description is self-consistent, and that different system descriptions are consistent and complete with respect to each other. </li></ul><ul><li>Verifying: building the product right. </li></ul><ul><li>For verification in the UML use: </li></ul><ul><ul><li>Class, interaction and statchart diagrams </li></ul></ul>analysis design code test
  109. 109. Testing Summary <ul><li>Validation is the process of checking that each system description is consistent with the customer’s requirements. </li></ul><ul><li>Validating: building the right product. </li></ul><ul><li>For validation in the UML use: </li></ul><ul><ul><li>Use case diagrams, Activity Diagrams to capture user processes or workflows. </li></ul></ul>analysis design code test
  110. 110. Testing Summary <ul><li>Validation is the process of checking that each system description is consistent with the customer’s requirements. </li></ul><ul><li>Validating: building the right product. </li></ul><ul><li>For validation in the UML use: </li></ul><ul><ul><li>Use case diagrams, Activity Diagrams to capture user processes or workflows. </li></ul></ul>analysis design code test