Skip to content
Advertisement

Tag: spock

Can I add a delay to a call to a Stub method in Spock?

I’m using the Spock Framework to test some Java classes. One thing I need to do is add a delay to a Stub method that I’m calling, in order to simulate a long-running method. Is this possible? This looks possible using Mockito: Can I delay a stubbed method response with Mockito?. Is it possible using Spock? Answer Spock is a

Spock throw exception test

I test Java code with Spock. I test this code: I wrote test: And it fails because AnotherCustomExceptio is thrown. But in the try{}catch block I catch this exception and throw a CustomException so I expected that my method will throw CustomException and not AnotherCustomExceptio. How do I test it? Answer I believe your then block needs to be fixed.

Advertisement