testcontainers/testcontainers-spock

Cannot declare custom package name in test classes

amimas opened this issue · 2 comments

Hi there,

I'm running into a very odd behaviour. Not sure if I've done something incorrectly. Would you be able to please take a quick look at this?

Here's my gradle build script that brings in testcontainers-spock

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

apply plugin: 'groovy'

dependencies {
    compile 'com.github.testcontainers:testcontainers-spock:673320b'
    compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'

    testCompile 'org.apache.httpcomponents:httpclient:4.5.2'
}

///////// TEST CONFIGURATION /////////
test {
	testLogging {
		events "failed", "passed", "skipped", "started"
		exceptionFormat "full"
		showStackTraces true
        
		// when running Gradle with a '--info', display the stanard streams
		info.showStandardStreams = true
	}
}

I have a test class in <gradle-project>/src/test/groovy/my/org/docker/ directory. The test file is named MyIntegrationSpec.groovy

Inside MyIntegrationSpec.groovy, I can't seem to declare a custom package name. For example: package com.my.org.docker.service.test returns following error about @TestContainers not resolving. The only way my tests will execute is if I declare the package name as package com.groovycoder.spockdockerextension

Did I miss any particular configuration in my build? I also tried to import com.groovycoder.spockdockerextension but that doesn't work either. I get an additional error about not being able to resolve spockdockerextension class

unable to resolve class Testcontainers ,  unable to find class for annotation
 @ line 28, column 1.
   @Testcontainers
   ^

You should add the testcontainers-spock dependency as testCompile, but it should also work with compile in this case. Can you share the project on Github? I could take a look into it.

But you of course need to import the package.

Thank you for the pointers. I added testcontainers-spock as testcompile dependency and also imported package in my test class like this:

Import com.groovycoder.spockdockerextension.*

That resolved the issue. I think previously my import was incorrect and that's why it didn't work.