The "demand" of the static method does not work with the "new MockFor" in Grails-3.2.4 "Junit Testing"

Can someone please let me know how to require static class methods. I tried with the code below and it does not work with it:

import groovy.mock.interceptor.MockFor

final mockCl = new MockFor(ClassName) 
mockCl.demand.static.methodName(1) { return 'something' } 

However, he gives below exceptions:

groovy.lang.MissingPropertyException: No such property: static for   class: groovy.mock.interceptor.Demand at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53) at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:87)

Can someone tell me how to mock static methods in JUNIT with grails 3.

+4
source share
1 answer

Try:

YourClass.metaClass.static.methodName = { return 'something }
+2
source

Source: https://habr.com/ru/post/1669551/


All Articles