Application Development and Automation 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: 
Read only

How Unit Test works on Open SQL?

ArcherZhang
Product and Topic Expert
Product and Topic Expert
0 Likes
3,528

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

1 ACCEPTED SOLUTION
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
3,214

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.

15 REPLIES 15
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
3,215

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.

Read only

0 Likes
3,214

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

Read only

3,214

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

But why not some teasing 😉

Read only

3,214

oh yes please please 🙂

Read only

3,214

Don't Let Me Be Misunderstood ...

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

Read only

3,214

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

Read only

0 Likes
3,214

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?

Read only

0 Likes
3,214

I would never have guessed that SAP would be working on another version 😉

Read only

0 Likes
3,214

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?

Read only

3,214

Yeah, of course, but

Read only

0 Likes
3,214

You're probably right.

Read only

0 Likes
3,214

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

Read only

Sandra_Rossi
Active Contributor
3,214

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.

Read only

0 Likes
3,214

maybe you can 'select' again after 'ins/del/upd' of D, and then compare the ACT and EXP in your test method. to verify if the update openSQL actually works.