Skip to Content

Creating external locks for Unit-tests

I would like to do some unit-tests considering external locks. As this is the locking class itself I would ideally like to create SM12 locks which look like coming form another LUW and then let my own locking fail. As this test the lock-class, I would like to really create the locks realistically.

The unit test is for a Locking class in a BOPF-based application.

PS: I know, is not exactly a unit test as it not only tests the coding, however I would like to use the unit test framework here.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Feb 24 at 06:06 PM

    As a matter of interest, how are you locking a BOPF object?

    I tried to implement an explicit lock function in BOPF before, but it's an internal action and SAP actively blocks the use of those. So the only SAP-sanctioned way I am aware of is an exclusive use read.

    Anyhow, to your question: If your lock service does the actual lock in a dedicated method, you can override this in your unit test and simulate locks. I have done this and it works well, the lock unit test class basically has the lock state and user as attributes instead of an enqueue. This does not do an enqueue at the database, but I think it's a reasonable assumption that we do not need to test that (Otherwise we might as well start testing SELECT statements and everything else).

    Add comment
    10|10000 characters needed characters exceeded

    • A complete BOPF mockup can be done, have a look at /bobf/cl_sadl_entity_transact for an impressive unit test.

      There are a few other nice gems around, look at classes of package /BOPF/TOOLS and so some where-used searching.

      I really like the idea but effort vs priority equation didn't balance at the time I looked at it so I didn't pursue it further.

      In our scenario we had to lock outside the BOPF framework anyway because access via the Gateway immediately releases the enqueue. So the lock service was within our custom BOPF framework (retrieve with enqueue, if successful then z-lock) . Via injection it is possible to supply a test service to the lock factory and thus cover an entire end to end scenario across several objects.