- NTT DATA Americas Integration Americas Onshore Offshore – 17,000 employees and $1.3B in revenues – Offering clients more options through increased depth and scale across: • Consulting & Systems Integration • Applications Services / ERP • Infrastructure Services • BPO Services • BI, Analytics & Performance Mgmt • Strategic Staffing – Balanced Industry depth in healthcare, commercial, financial and public sector – Successful long-term relationships with rich and diverse customer base – Balanced global delivery model that maximizes consistency and cost efficiencies ‘NTT DATA Your Innovation Partner, Anywhere around the world’
There is an urgent need for an agile programming strategy that can help customer/businesses with following benefits. Reduce the software development costs Improve software reliability Decrease development time Working application product Better Return On Investment “Test-driven development (TDD) is a software development strategy that requires that automated tests be written prior to writing functional code in small, rapid iterations.”
how TDD enables the writing of software that has better structure, in less time and with fewer defects. Discover how TDD results in better code design, usability design, safety net, instant feedback, modularity and documentation. Learn about the techniques and best practices to make it almost impossible to deliver bugs in the next software project.
Development Quality Assurance Integration & System Testing Number of Bugs Time No Feedback Without TDD Done ? Traditional Development Quality Assurance
Done Sooner ! Development Quality Assurance Integration & System Testing Number of Bugs Time No Feedback Continuous Feedback Without TDD With TDD Done ? Traditional TDD Development Development Quality Assurance Investment Life Cycle Benefit Net Return ROI = Life Cycle Benefit - Investment Investment
(cont’d) Better Code Design Usable Code Safety Net Modularity Instant Feedback Increased Productivity WYGIWYM (What You Get Is What You Meant) Documentation
is Test Driven Development (TDD)? Test Driven Development (TDD) is a software development technique and one of the aspects of Extreme Programming (XP). TDD is a design methodology. TDD is NOT about testing. TDD is a software development technique that uses short development iterations based on pre-written test cases that define desired improvements or new functions. TDD is about design and development. The process of designing software by writing a validating test before the code. TDD is a technique whereby you write your test cases before you write any implementation code. These tests drive or dictate the code that is developed.
Why TDD? (Cont’d) The test is the executable specification. You start visualizing the goal first, design the API, then later think about the possible implementation. You develop just enough. You get to the goal as quick as possible. You don’t develop unnecessary code. There is no code without a test. There is no test without a user requirement.
Why TDD? (Cont’d) Once you get test working, you know it is working. The test gives us the courage to refactor. It’s more fun that way, it reduces fear and builds confidence. “Regression testing = Stable software = Quality software”
Mantra… Write a single Unit Test for a very small piece of functionality and then Compile/Check syntax/Run and see it fails (RED). Write the simplest amount of code that will make the test compile and pass (GREEN). REFACTOR the code and/or tests to improve the design and still pass (GREEN). Kent Beck writes in his book "Test-Driven Development: By Example” as Red/Green/Refactor – the TDD mantra.
TDD help? TDD helps you produce clean working code that fulfills requirements. Write Test Code Code that fulfills requirements. Write Functional/Production Code Working code that fulfills requirements. Refactor Clean working code that fulfills requirements. Refactoring? “A change to the system that leaves its behavior unchanged, but enhances some nonfunctional quality – simplicity, flexibility, understandability, performance” - (Kent Beck, Extreme Programming Explained).
of TDD (In Practice) Write a Test Run the Test Write (just enough) Production Code to compile Run the Test Run the Test Write (just enough) Production Code to pass Refactoring Start
What it takes to adopt TDD? Requires good knowledge on Object Oriented Concepts. Requires minimum knowledge on ABAP Objects. Requires minimum SAP NetWeaver 2004 version. Prior version don’t have the Unit Testing Framework available. Requires Unit-Testing Framework (Built into ABAP workbench from SAP NetWeaver 2004 onwards) Requires better coding techniques to write clean code. Requires real commitment and discipline to follow this process, in order to get better quality results.
(cont’d) Executing ABAP Unit Test Menu "Program->Test->Unit Test" or by pressing Ctrl+Shift+F10. It is important that the system is configured in such a way that it allows the ABAP Unit tests to be performed. This means completing the configuration in transaction SAUNIT_CLIENT_SETUP, as well as setting the profile parameter abap/test_generation equal to ON. This profile parameter should be defined by the SAP NetWeaver administrator for the system.
(cont’d) Understanding ABAP Unit Result Display ABAP Unit Test Overview (On the left hand side of the result display) The test overview section provides a simple overview of all of the tests that were executed and includes the aggregate status of each test. It also displays the number of assertions and the assertion error level for each test.
(cont’d) Understanding ABAP Unit Result Display (cont’d) ABAP Unit Assertion Messages (On the top right hand side of the result display) The messages section provides a listing of all of the assertion messages that were logged during the test. The message displayed here come from passing the failure text to the MSG parameter when calling one of the ASSERT methods. By double-clicking on an entry, the detail of the assertion message is shown in the detail section of ABAP Unit result display.
(cont’d) Understanding ABAP Unit Result Display (cont’d) ABAP Unit Message Detail (On the bottom right hand side of the result display) The message details section provides details for each assertion message. To see where exactly the failure occurred in our test, we need to click on the link (Line: 44) provided under Stack node.
(cont’d) Understanding ABAP Unit Result Display (cont’d) Assertion failure location (Clicking on the Link, i.e. "Line: 44") Assertion failed, because we are expecting '45' but the resulted TEST_AMOUNT was 300, which is wrong. This resulted value is calculated inside the form routine CALC_TIP_AMOUNT.
(cont’d) Understanding ABAP Unit Result Display (cont’d) Fixing the issue/error in CALC_TIP_AMOUNT form routine and activating it. Running again ABAP Unit test by pressing Ctrl+Shift+F10 will result in successful message. ABAP Unit can help us detect the failures/errors easily and can be tracked down. With ABAP Unit tests in place and with a open mind to simple analysis will bring great value and confidence. All developers will love to use once they understand its easiness and the value it brings to the code quality and project.
First Law Write no production code unless to pass a failing test. Second Law Write no more of a test than is sufficient to make it fail. Third Law Write no more production code than is sufficient to pass a failing test.
Unit testing frameworks are quite popular in the object- oriented programming world. Frameworks like JUnit (for Java), SUnit (for Smalltalk), and Test::Unit (for Ruby) provide a rich set of functionality. Various code-driven testing frameworks are collectively know as xUnit. Unit tests are at the core of TDD. Unit testing frameworks helps simplify the process of Unit testing and the goal is to make writing test as painless as possible. As of SAP NetWeaver 2004, ABAP Unit is available as Unit testing framework, which takes the ideas of JUnit from Java environment and applies them to ABAP.
Design Methodology ABAP Unit is a test tool highly integrated directly in the ABAP runtime environment. ABAP Unit can be used for executing module/unit tests – i.e. for checking the functions of code sections in a program. ABAP Units are implemented using the ABAP programming language. Therefore, the advantage is that there is no need to learn any additional test scripting language. ABAP Unit is standardized process to test and it can be put into a QA process and used for automatic and rigorous testing.
Design Methodology (cont’d) Advantages of ABAP Unit. The tests are programmed in ABAP. Additional test script language is not required. The tests are developed in the ABAP development environment. Additional interface operation is not required. In the development phase, tests can be called directly within the editor. The test execution can be automated. Mass tests are enabled by integration into the Code Inspector tool.
Design Methodology (cont’d) ABAP Unit implementation. Tests are developed in the form of test methods in test classes during or even before the actual program development. Test classes are local classes of the ABAP program to be tested and are thus a part of that program, which also ensures that the version integrity is maintained after transports. Developers incorporate tests and test conditions (fixtures) into their programs and they themselves executes these tests. Since the implemented code is first tested by developers themselves the higher quality product can be expected.
Design Methodology (cont’d) Main Components of ABAP Unit (cont’d) Test Attributes. Test attributes are management attributes of test classes, which are taken into account during test execution. The test attributes of local test classes are defined using pseudo comments in the CLASS statement immediately following the FOR TESTING addition. You can specify one pseudo comment per line in the program and note that they are Case-Sensitive.
Design Methodology (cont’d) Main Components of ABAP Unit (cont’d) Test Fixtures. Fixtures is a test configuration that is created before a test method is called and also ensures a unique test behavior. Fixtures consists of test data, test objects, resources, and connections. The complete set of these test objects is called the test fixture. Fixtures are nothing more than private method defined in the test class, which are used to set up specific conditions for the test. These method names are reserved and are triggered automatically by the ABAP runtime.
Design Methodology (cont’d) ABAP Unit Load Concepts When this developed production code and test code are moved to production environment, the compiler and the run time will just ignore all the test code.
Myth #1 : Will it not double the development time if we write unit tests? - No. Writing unit tests is a investment towards time savings over the lifetime of the project.
(cont’d) Myth #2 : All my unit tests just get outdated over a time! - No. Unit tests are not parallel to your code like documentation. You will be driving your code with them.
start with a test for better API design. Write no production code unless to pass a failing test. Write no more of a test than is sufficient to make it fail. Always write simplest possible solution to make test pass. Write no more production code than is sufficient to pass a failing test. Before Refactoring, always run the ABAP Unit test to make sure all the tests are passed and is all working. Run ABAP Unit test very often to make sure nothing broken in the process. Remember “Your tests should drive or dictate the code that is being developed”
now know what is TDD and how it helps in designing better API for producing quality applications. TDD helps building application that has better structure, in less time with better code design and usability design. TDD process produces instant feedback, which acts as safety net when making changes. The Unit tests helps in writing modularized code and also helps as a documentation. Learnt about 3 Laws of TDD and TDD Mantra. ABAP Unit – Unit testing framework & Best Practices.
ABAP Unit, A Unit Testing Framework is built into ABAP Workbench from SAP NetWeaver 2004 onwards. ABAP Unit is a test tool highly integrated directly in the ABAP runtime environment. ABAP Units are implemented using the ABAP programming lang. The tests are programmed and developed in ABAP development environment. In a production system the ABAP Unit tests are not part of the productive program load and hence no performance or security drawbacks. TDD is a design methodology and helps you produce clean working code to build the quality product. The TDD Mantra – Red, Green & Refactor.
Development: By Example Kent Beck, Addison-Wesley, 2003. Test-Driven Development: A Practical Guide Dave Astels, Prentice-Hall, 2003. Refactoring: Improving the Design of Existing Code Martin Fowler, Addison-Wesley, 1999 Test Driven Development with ABAP Objects (Upcoming) JK (JayaKumar Pedapudi), SAPPRESS. https://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Unit http://xprogramming.com/index.php
you for participating. SESSION CODE: 0913 Please remember to complete and return your evaluation form following this session. For ongoing education on this area of focus, visit the Year-Round Community page at www.asug.com/yrc
– A Design Methodology Main Components of ABAP Unit ABAP Unit Load Concepts ASSERT_EQUALS - Method parameters details Unit Test Flow Control in case of Failure
A Design Methodology Main Components of ABAP Unit Test Classes. Test classes are local classes in ABAP programs, with the exception of type groups and interface pools (i.e., executable programs, class pools, function groups, module pools, and subroutine pools). These test classes are not generated in productive systems and therefore cannot be executed. Hence it is safe and there is no performance issue caused due to the test classes in production system. As of SAP NetWeaver 7.0, test classes can be implemented using the global classes. These global classes are abstract and can only be used in local test classes.
A Design Methodology (cont’d) Main Components of ABAP Unit (cont’d) Test Methods. Test methods are parameter less (i.e., do not have method signature) instance methods of test class, which are used to trigger an ABAP Unit test. These test methods are defined using the FOR TESTING addition to the METHODS statement in the CLASS definition block. Each test method corresponds to an ABAP Unit test, which is responsible to trigger some block of production code in object you are testing. Test methods should be private, or protected if the methods are inherited.
A Design Methodology (cont’d) ABAP Unit Load Concepts Production Code and Test Code. The definition of test classes divides a program into production code and test code. Test code (i.e., Test classes and their components) are not generated in production systems. So you cannot access a test class from the production code. On the other hand, test classes can access all addressable components of a program and other test classes. In a production system the ABAP Unit tests are not part of the productive program load. Hence there are no performance or security drawbacks. Since the tests are maintained along with corresponding production code, the code transportation would be easier.
A Design Methodology (cont’d) ASSERT_EQUALS - Method parameters details This static method ASSERT_EQUALS is used to ensures the equality of two data objects. Two data objects in comparison can be a string or any data type object or an internal table, etc.
are planning to test after you’ve developed the system, you won’t have enough time for testing. Write the tests before the actual code! If things get complicated, you might fear that “the system” doesn’t work. You loose the confidence. Execute the tests and get positive feedback (everything still works) or Get instance feedback to locate the point that does not / no longer work. If you don’t have tests for the code, you shouldn’t use it / release it / ship it. This can’t happen if you write the test first (so you develop better test coverage).
you’re overwhelmed by the complexity, you get frustrated. Start with the simplest thing and proceed in tiny steps! If you are planning to skip the regression test, because you don’t have time, then they are more chances that application may go useless. Writing tests along with development, helps in performing regression tests. If performance is only considered towards the end of the project, then you won’t be able to just “add a little more performance” to the system. Re-use unit tests for performance tests even during the development and don’t start with performance tests late in the project!