uweku / mocka Goto Github PK
View Code? Open in Web Editor NEWmockA is a free Mocking Framework for ABAP
License: Apache License 2.0
mockA is a free Mocking Framework for ABAP
License: Apache License 2.0
Hi,
I am trying out this framework and so far I think it's very neat! Exactly what has been missing in ABAP. I have one question regarding optional / default value importing parameters.
It seems that the framework will register a call only for actually passed parameters, which I think is fine. But the IS SUPPLIED condition in the generated mock method returns false for parameters with default values. I think it should be registered though, because a default parameter is always passed even if (or particularly when) there is no actual parameter.
Secondly, the HAS_BEEN_CALLED_WITH method will build a method call with all parameters, regardless whether they are optional / have default values or not, and compares this to the actual method calls that have happenend. I don't see how this condtion can ever be fulfilled if I leave out optional parameters in the actual implementation.
I hope the description of my problem is clear.. Did I miss something in the documentation (i.e. is this known / intended behaviour) or is this a bug?
Kind regards & thank you for this framework.
Max
If you call the methods
changes
exports
raises_by_name
with
with_changing
These don't get mocked.
I've added the following code
finalize_current_method_sign( ).
To the end of each method before the
ro_mocker_method = me.
statement to get this to work.
I am creating a mock for a class 'ZCL_RECEIVABLE_CALCULATOR_RBL' which implements an interface 'ZIF_CFSR_RECEIVABLE_CALCULATOR'. When I try to create a fake for the method 'ZIF_CFSR_RECEIVABLE_CALCULATORCALCULATE' the mock cuts the total method name off at 30 characters: 'ZIF_CFSR_RECEIVABLE_CALCULATORCAL' and generating the mock fails.
Hi Uwe,
do you plan to support installation / Updating mockA with abapGit?
regards
Micha
test ZTEST_CL_MOCKA_MOCKER / FAKE_INCLUDED_INTERFACE_METHOD( )
Hi
Line 175 of ZIF_MOCKA_MOCKER~GENERATE_MOCKUP checks the visibility field for a 0 to determine if the attribute is a private one or not.
On our release of SAP this value is an 'I'.
I've changed my code from
IF <ls_attribute>-visibility = 'I'."no mocking of private attributes
to
IF <ls_attribute>-visibility = 'I' or '0'."no mocking of private attributes
Thanx
Nath
Mocking if_http_client, it seems it's actually not possible as I get an error that using old exception types isn't allowed. Methods like IF_HTTP_CLIENT~CLOSE use old exception types so the generated code cannot compile.
Old exception types are not yet supportedd, however, generating the mockup should not fail.
Proposed solution skip output of
DATA lo_cx_exc TYPE REF TO cx_root.
IF lv_exception IS NOT INITIAL.
TRANSLATE lv_exception TO UPPER CASE.
CREATE OBJECT lo_cx_exc TYPE (lv_exception).
RAISE EXCEPTION lo_cx_exc.
ENDIF.
.
in method GENERATE_MOCKUP in case the method to be mocked contains old style exceptions
Hallo Uwe,
bei einer Testkonstellation habe ich festgestellt, dass je Testklasse nur genau 1 Mock einer Klasse erzeugt werden kann.
Aufgefallen ist dies bei einer Methode ohne Parameter, die abhängig von der simulierten DB-Situation einmal true und einmal false liefern soll.
Dies hat so nicht funktioniert, da es nicht möglich ist, einen weiteren Mock für dieselbe Klasse zu erzeugen. Der bereits bestehende Mock wird recycelt (Limit Subroutine-Pool).
Wäre es möglich, das Framework schaltbar zu machen, um das Recycling zu aktivieren oder deaktivieren?
Wobei sich mir generell die Frage stellt, ob in einer Testklasse jemals mehr als 36 Mocks einer Klasse erzeugt werden müssen.
Hallo Sven,
ja, das Verhalten ist korrekt beschrieben. Bei Interfaces macht das meines Wissens nach keine Probleme, weil einfach alle Methoden implementiert werden. Handelt es sich bei deinem Testfall um eine nicht finale Klasse, deren Verhalten übersteuert werden soll?
Leider ist bei Klassen so, dass von mockA nur die Methoden redefiniert werden, die tatsächlich beim ersten Generieren zu simulieren sind.
Man könnte die Wiederverwendung der generierten Quellcodes bei Klassen generell ausschalten, was das Problem lösen würde.
An die Restriktion von 36 Mocks je Unit Test bin ich jedenfalls selbst schon gestoßen :-)
Viele Grüße,
Uwe
As of now, the ASSERT_EQUALS method in ZCL_MOCKA_VALUE_COMPARISON compares actual method input parameters with the registered parameters.
However this operation might fail as registerd parameters and actual method parameters might not be comparable. It can even cause a short dump.
The current implementation catches CX_ROOT, but comparing the values can still cause a short dump in some cases.
A check logic just like the local class lcl_Check in CL_AUNIT_ASSERT provides for ABAP Unit might be better and more error-proof.
I found that mockA works well with 7.01 with some minor changes to the sources:
append 'type-pools: abap.' to lt_code.
Have fun!
I think it would be nice to have a possibility to automatically generate function call wrappers.
Do you see a way to extend the mockA framework to be able to do this?
Hi
I cannot install mockA using the latest SAPLink, I've downloaded the latest daily build, but keep getting the error message::
"You have an empty nugget" everytime I try,
Regards
If you run unit tests in the ATC or by right clicking on the object and going to Execute->Unit tests
If you have multiple test methods then the mock object doesn't get regenerated for the next unit test method.
This is because the static variables
MV_MOCK_COUNT.
MT_GENERATED_CLASSES
do not get cleared down between method calls and as a result the subroutine pool doesn't get regenerated.
I've created a method FREE in the interface ZIF_MOCKA_MOCKER, which I've implemented to clear down these variables. I call this method before I leave the testing method.
This could be an artefact of being on a different system to yourself.
Thanx
Nath
In SCN, Ethan mentioned: Are there plans to mock properties directly? I know, it's a no-no to have public properties, but many of SAP's built-in classes use them - for example if_http_client->response.
When mocking an interface that aliases methods from another interface (if_http_reponse aliases methods from if_http_entity), it seems you need to mock the full method from the other interface, not the aliased method. If you mock the interface method, when your code calls the alias it will get the value you mock. But if you mock the alias you get nothing, or so it seems to me.
So, if you want to mock if_http_response->get_cdata( ), you need to lo_mocker->method('if_http_entity~get_cdata')->return('Foo').
This behaviour
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.