I'm creating a java app for raspberry pi using Pi4j.
The application fails to run out of raspbian OS due to lack of GPIO drivers in place. That's why when I run my spock integration tests I need to mock/stub a bean which relies on original Pi4j API. My problem is that the bean itself is mocked but the stubbed method returns null instead of the value I define.
@SpringBootTest
class RoboApplicationTest extends Specification {
@Autowired
ApplicationContext context
@SpringBean
GpioController gpioController = Stub()
def "test context loads"() {
given:
gpioController.provisionDigitalInputPin(_, _, _) >> { throw new RuntimeException("I'm stubbed!") }
expect:
context != null
context.containsBean('gpioController')
}
}
Instead of throwing an exception or returning anything I put there "provisionDigitalInputPin" method returns null that causes further NPE.
You can find the whole app here: https://github.com/ahlinist/raspberry-pi4j/tree/feature/integration-tests
I'm trying to achieve the result described here: https://github.com/spockframework/spock/blob/master/spock-spring/boot-test/src/test/groovy/org/spockframework/boot/SpringBeanIntegrationSpec.groovy
I've tried many approaches with no result. Similar test with Mockito works well. What am I missing?
Update: To run integration tests execute:
./gradlew integrationTest
Update 2: The corresponding Spock ticket #1084 has been created on GitHub.