unit testing - How do I mock a static method in final class -
i have code has static method within final class. trying mock method. have tried doing few things..
public final class class1{ public static void dosomething(){ } }
how can mock dosomething()? have tried..
class1 c1=powermockito.mock(class1.class) powermockito.mocksatic(class1.class); mockito.donothing().when(c1).dosomething();
this gives me error:
org.mockito.exceptions.misusing.unfinishedstubbingexception: unfinished stubbing detected here: -> @ com.cerner.devcenter.wag.texthandler.assessmentfactory_test.testgetgradereport_htmlassessment(assessmentfactory_test.java:63) e.g. thenreturn() may missing. examples of right stubbing: when(mock.isok()).thenreturn(true); when(mock.isok()).thenthrow(exception); dothrow(exception).when(mock).somevoidmethod(); hints: 1. missing thenreturn() 2. trying stub final method, naughty developer! @ org.powermock.api.mockito.internal.invocation.mockitomethodinvocationcontrol.performintercept(mockitomethodinvocationcontrol.java:260)
most used testing framework junit 4. if using need annotate test class with:
@runwith( powermockrunner.class ) @preparefortest( class1.class )
than
powermockito.mocksatic(class1.class); mockito.donothing().when(c1).dosomething(); mockito.when(class1.dosomething()).thenreturn(fakedvalue); // phone call of static method required mock powermockito.donothing().when(class1.class); class1.dosomething();
unit-testing mockito static-methods final
No comments:
Post a Comment