Skip to Content
-2

How Unit Test works on Open SQL?

Jun 13, 2017 at 03:06 AM

124

avatar image

Hi experts,

Say I want a DB handler class as below, in which method is pure Open SQL statement.

CLASS lcl_mara_db_handler IMPLEMETATION.

METHOD update_mara.

MODIFY mara FROM is_mara.

ENDMETHOD.

METHOD insert_mara.

INSERT.........

ENDMETHOD.

.......

ENDCLASS.

How can I write Unit Test first, as the decency is DB, do I need to consider that a different DB could return a different result? Or not necessary to consider the Unit Test on this leave?

BRs,

Archer

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Horst Keller
Jun 13, 2017 at 04:13 AM
2

For that, we have test seams and injections.

https://blogs.sap.com/2015/10/23/abap-news-for-750-test-seams-and-injections

Since you are with SAP, you might also check the 7.52 documentation for another new possibility.

Show 12 Share
10 |10000 characters needed characters left characters exceeded

hmm can you tell more about that ("another new possibility"), Horst? :D

0

Nope. I'm not allowed to do so before 7.52 is available outside SAP.

But why not some teasing ;-)

2

oh yes please please :)

1

Don't Let Me Be Misunderstood ...

The teasing already happened by mentioning 7.52 at all ...

1

I would never have guessed that SAP would be working on another version ;-)

0

Hi Sandra,

how to enable (integration) testing with OpenSQL? I would presume the ABAP Unit framework will be enhanced to

  • enable writing a fixture in the DB table
  • run the tests
  • delete the test data after LUW.

What do you think? Horst can vote me down to stop fake news :)

JNN

1

One can "like" a comment, but one can only downvote an answer. One of the many peculiarities of the new SCN platform.

I like your thinking though, perhaps something like DB table overloading?

0

You're probably right.

0

Well Horst Keller it is official now:

ABAP - Keyword Documentation → ABAP - Reference → Processing External Data → ABAP Database Accesses → Open SQL →Open SQL - System Classes → CL_OSQL_REPLACE - Replacement Service

I have found the class in Netweaver 7.51. Is it the same functionality?

JNN

0
0

I thought the test seam / injection thing was only a workaround to make legacy code testable without rewriting it.

In the example above I would have abstracted the functionality to an interface and implemented it twice, having a productive implementation that uses opensql and a (possibly local) test implementation with dummy data / return values (maybe even using cl_abap_testdouble). Is that not the recommended approach?

0

Yeah, of course, but

1
Sandra Rossi Jun 13, 2017 at 05:41 AM
1

OpenSQL gives the same result whatever the database is, that's the reason of being of OpenSQL (in answer to "do I need to consider that a different DB could return a different result?") I probably didn't get your point, sorry.

Share
10 |10000 characters needed characters left characters exceeded