This is a test message to test the length of the message box.
Login
ABAP Unit Testable Code
Created by Software-Heroes

ABAP Unit - Testable Code (Part 2)

258

This article is about test isolation and how it makes our code more testable.



This week the article is a bit shorter and we will only bring you closer to the topic of test isolation. Why is it important to program your own objects in a testable manner and how can you reduce the dependencies on other objects.

 

Term

Test isolation is primarily about the use of test doubles to control dependent components. Without control, these can influence our own tests in different ways:

  • Slow - Our own tests can become correspondingly slow due to unknown logic, as we cannot influence the runtime
  • Defect - Components can be under development or broken due to an extension, so our test cases are automatically also faulty, although our logic still works
  • Output - Other components can cause unwanted outputs (display, e-mail, generation of receipts, etc.)
  • Input - There may be unwanted inputs or popups that pause or crash your tests

 

There are many other reasons why it is best to isolate such dependent components. However, the examples are intended to roughly show what can go wrong when implementing the tests.

 

Identification

Accordingly, such dependent components must also be identified. These can be, for example:

  • Instantiating another class
  • Interaction with the database
  • Create and use BAdI
  • Calling a function module
  • Determination and comparison of the current time

 

Methodology

How do you achieve test isolation? There is a very simple rule here, use an interface for each class and work with this in the calling code. For data management and transfer in methods, use the data type of the implementing class, but always only use the interface. In the end, the calling code does not care which object is hidden behind the reference, as long as the object uses the interface.

Hint: The creation of an interface for each class takes a lot of time and discipline, but creates just as many new objects in the system. The effort is worth it and provides you with clean and testable objects for the future.

 

Conclusion

In this article we showed you how to separate the code and how interfaces support you in writing testable code. We'll take a closer look at dependency injection in the next article.


Included topics:
ABAP UnitABAPUnit TestsTestable CodeTest Isolation
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP Unit - Test execution

Category - ABAP

What options are there for executing ABAP Unit and what hidden functions might you not know about? More details about the different modes in this article.

06/25/2024

ABAP Unit - Automation

Category - ABAP

When do objects break during development and what side effects can adjustments have? In this article we take a closer look at the topic.

01/05/2024

ABAP Unit - TDF (Function Double)

Category - ABAP

In this article, let's take a look at how we can deal with function modules as dependencies without testing them as well.

04/07/2023

RAP - ABAP Unit (Service)

Category - ABAP

How do you actually test the service of an interface or RAP app automatically? In this article we look at unit tests for OData services.

01/20/2023

RAP - ABAP Unit (Business Object)

Category - ABAP

At this point, we'll take a look at how we can test our RAP Business Object automatically in order to check all important functions at the touch of a button.

01/13/2023