gradle testFixturesImplementation cannot find symbol Mockito

1000 views Asked by At

I am trying to set up testFixtures. I have a class that until now was in src/test/ and now I'm trying to turn it into fixrure.

In build.gradle I added:

plugins {
    id 'java-library'
    id "java-test-fixtures"
}

I moved the class from src/test/java/com/example/AmazonTestConfig.java to src/testFixtures/java/com/example/AmazonTestConfig.java

And in the dependencies I had to add a few things, i.e:

dependencies {
    ...
    testFixturesImplementation project(':MyCommon')
    testFixturesImplementation 'com.amazonaws:aws-java-sdk-s3:1.12.75'
    testFixturesImplementation 'junit:junit:4.13'
    testFixturesImplementation 'org.mockito:mockito-all:1.9.0'
}

The first 3 dependencies work, but the mockito doesn't. Here's part of my Foo.java:

import static org.mockito.Mockito.*;

@Ignore
public interface AmazonTestConfig {

    default void setS3FilesDal(ServerEngine engineMock) {
        ICloudStorage s3FilesDal = new AWSStorage();
        CloudServices cloudServicesMock = Mockito.mock(CloudServices.class);
        Mockito.when(engineMock.getCloudServices()).thenReturn(cloudServicesMock);
        Mockito.when(cloudServicesMock.getStorage()).thenReturn(s3FilesDal);
    }
}

But I get the following compilation error:

myproject/src/testFixtures/java/com/example/AmazonTestConfig.java:23: error: cannot find symbol
        CloudServices cloudServicesMock = Mockito.mock(CloudServices.class);
                                          ^
  symbol:   variable Mockito
  location: interface AmazonTestConfig
1

There are 1 answers

0
Gavriel On

I'm not sure why, but changing:

import static org.mockito.Mockito.*;

to:

import org.mockito.Matchers;
import org.mockito.Mockito;

fixed the problem. Looks like a bug in gradle.