goldmansachs/jdmn

q/a | setting time in tests

Closed this issue · 4 comments

Expected Behavior

When writing expressions that use feel functions like now(), we want to write tests against this date logic. Additionally, even if we trust that now works as expected, we still may want to test the entire decision flow and if it depends on now() then we need to do something about it.

Actual Behavior

In the generated Java object that holds the feel expression, we see that the generated drg element eventually delegates to now() in a super class which contains dateTimeLib for instance. We don't see an opportunity control the clock in a unit test environment.

jDMN Version where this issue was observed

<jdmn.version>8.2.3</jdmn.version>

We are using the Java generator.

Workaround

Right now we supply our own currentDateTime input variable.

Question

Is there support for this kind of testing?

The testing of usage of now() and today() can be done by mocking using either stubs or existing mock frameworks.

I hope this helps,

Is there an example used in jdmn? Not sure how we can supply a stub or mock with how the datetimelib is encapsulated.

You can create a new class that extends the decision that invokes the today() / now() and override the today() or now() method to return the value you want to test.

Gotcha, yeah gets past the immediate use case.

What are your thoughts on providing a clock to the EvaluationContext? We can subclass, but then we need to remember to override today or now on every intermediate decision object.