GUnit and Mocking frameworks

323 views Asked by At

Guidewire cloud standards states that mocking (mockito, easymock etc.) is not fully supported and test stubs are recommended. Is that right and why?

We are planning to build a new Unit testing suite on Guidewire for PC, BC, CC. Also looking at migrating the applications to Cloud.

2

There are 2 answers

0
Gwisard On BEST ANSWER

That is correct Ajith, Guidewire platform have never fully supported mocking. The main reason lays in the construction of the persistence framework and the lack of dependency injection throughout the platform. Funny enough there are easymock libraries shipped with the OOTB There are some successful attempts that I've made (and others I know) in the past to mock certain aspects in GOSU and they work fine. However when you try to do things like entity mocking of enhancements mocking then you will struggle big time and you are most likely to end up nowhere. Let me know if you need any further delve into the topic.

0
Edgar D. On

Many entities implement interfaces. If you use one of the interfaces as the parameter type of your function you can create mocks.

The Gosu structure is also a handy concept for testing. The structure just tests for the existence of the properties on an object. If you create structures to use as your parameter types, then mocking is simple.

An alternative approach that mitigates the issue with mocking is to use PCNeverPersistBundle for your tests. In many cases if running in a non-persistent bundle, you can just use entities.