Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP select data encapsulation

0 Kudos
407

Hi,

I'm quite new in ABAP and see a lot of ABAP methods or FMs with ABAP select statements reading data from the tables.

When it comes to testing and especially unit tests, it's almost impossible to write such a unit test, since the data coming from the tables is volatile and will change.

Somehow it can be achieved with test double framework. But database mocks are not possible, since we are still on

on ECC 7.5 and osql test double framework does not exist.

Question:

Is it still a good practice to have all these select statements directly in the methods or FMs, or would it be recommended to create something like a repository class with an interface to encapsulate the data access logic.

The idea then is to use the normal test double framework and create a mock object of the repository object for the unit tests.

Thank your very much for the ideas, answers and maybe experiences.

2 REPLIES 2

FredericGirod
Active Contributor
0 Kudos
256

And a dedicated class for data will help you to create a mock and test class using this data class

0 Kudos
256

Looks a bit like coming from ChatGPT 😉

Anyway, I know all the advantages and disadvantages, since in the Non-ABAP world it's very common.

But then I see any ABAP code, even SAP standard, I cannot see patterns like that. So my question goes more in the direction of:

Is it also in SAP - ABAP common practice to encapsulate data access?

Is it common to write Unit Tests especially create mock objects?

Thanks a lot.