I try to run my first Spock Test inside Eclipse, and it does not work.
I added all the Maven dependencies and plugins in my pom.xml, but when I run my test with jUnit, there is a popup windows with this Warning message : "No jUnit tests found".
Did you already seen this kind of message ?
What config has to be done, in order to run a Spock Test inside Eclipse ?
Thanks a lot.
Its same as running Junit test cases.
Right click on the class and run as 4Junit Test runner. see below for complete configurations and running the spock test.
Running Spock Framework with Eclipse, Gradle, Groovy: Source -
Krzysztof Goralski, blog
-Install Gradle Plugin, check it here
-Install Groovy-Eclipse for Juno or Indigo from Eclipse Marketplace (or maybe Groovy/Grails Tool Suite for Eclipse)
-Install Spock Plugin From Eclipse Marketplace if you want, check it here
-Import Project to Eclipse through Gradle Import
-Add these lines to build.gradle:
apply plugin: ‘groovy’
testCompile ‘org.spockframework:spock-spring:1.0-groovy-2.3’ (for Spring)
this is quite important, version can make some conflicts
-After this *.groovy and *.gradle files will problably looks different, Syntax colour highlightning etc. Remember that you can right click on for eg. build.gradle -> Open with -> Open With Minimalist gradle Editor etc.
-Probably you will need to make additional folder for *.groovy test files
Create new *.groovy file, class
-Basic test example, extends Specification from Spock framework and needs specific Annotations when running with Spring
-Now you can run it with JUnit from Eclipse
For integration tests you can’t use #RunWith(SpringJUnit4ClassRunner.class), and Context should looks like here #ContextConfiguration(locations = [ “/restTestContext.xml” ]) , not {} braces, but [ ]
-Spock can be used for Mocks too. Something like this: Subscriber subscriber1 = Mock() , subscriber1.isActive() >> true , So, remember >> operator for mocks.
Right click on the project > Properties > Java Build Bath > Add External Jars and add spock-core-0.6-groovy-1.8.jar and check if Groovy Libraries are there in Build Path or not. If not click on Add Library and select Groovy Runtime Libraries and restart Eclipse. Now you should be able to run. If still can't Run then try creating New Configuration and change the Test runner to Junit4 and Run it...
Check if the folder your tests are in is a source folder.
Related
I writing gradle plugin for code generation, and it's use groovy org.codehaus.groovy.runtime.ExtensionModule.
But extensions resolve on gradle (daemon) start stage, and add jar with META-INF/services/org.codehaus.groovy.runtime.ExtensionModule into build script classpath has no effect.
How to register ExtentionModule manually?
I don't believe you can, as it says in the documentation:
to use an extension, it has to be available on classpath, as compiled classes, before the code using it gets compiled
i've renamed my test folder to "test". Before it was set to AndroidTest and everything works. But i have a task from my superior that the test folder must be called "test". After i renamed the folder to test in android studio the test stopped running so i went into the run configuration for the test and specified teh package name but that did not help. Here are some details on issue:
and here is the build configuration i am running for the test:
The manifest does not have anything about test in it. This is just a dummy project i made. Do i need to enter something in the manifest ?
After reading the article provided in the comments i thought i'd share how one might resolved the issue:
Android studio does not know how to respond to our test runner unless we tell it. so i made a gradle task like the following:
when you run this gradle task it will run all test cases.
To explain, here we will cleanTest (which cleans all previous tests) then we will run the test task (its like doing gradle test on command line to run test). The test dont run again if they are successful so if you give it the option of --rerun-tasks then it will return the same test task. As for the --tests * option its used to specify which tests you want to run. in my case it was everything but you can specify a class path or even down to the method level here. very useful. so its like running this on the command line: gradle test --rerun-tasks
I have a Java project that has a lot of unit tests written in Groovy.I do not have the GDK installed and it still runs.
The project uses gradle and it has "apply plugin: groovy" in the build script but I was under the impression that it would just use groovyc which is definitely not installed.
How does this work?
Thanks
Inside your build.gradle file, inside the dependencies block, you will have a line probably like:
compile 'org.codehaus.groovy:groovy-all:2.4.1'
This line pulls in the specified version of groovy, and the groovy plugin uses it to compile your groovy code
I have the Groovy and Groovy Postbuild plugins installed in Jenkins (1.554) and have it set to automatically install Groovy 2.2.1 when needed.
After having a problem with a constructor signature I dug a little deeper and round that Jenkins is actually using 1.8.9 by running this through the groovysh CLI.
groovy> import org.codehaus.groovy.runtime.InvokerHelper
groovy> println InvokerHelper.version
It appears that the groovy post build plugin is also using 1.8.9 based on the error message I get when I try to run my script.
How can I update this? I have already set the groovy plugin to use 2.2.1. Thanks!
Groovy Postbuild plugins use the groovy version included in Jenkins (1.8.9). You can't change it.
The problem is the same as the system script in Groovy Plugin.
If you need a newer version of groovy a workaround is to do your work in a build (like Groovy Plugin purpose). Write some informations in a text file. And Read it in Post build step to do what you want with jenkins context (create badge, add summary, etc.)
Note that you can access to build workspace in post build step with:
manager.build.project.getWorkspace()
Hope it helps.
I installed Groovy v2.4.3 to /usr/share/groovy and then in my jenkins post-build task I reference my script as /usr/bin/groovy myscript.groovy similar to how #passionne described.
Is there any way to access Gradle groovy plugin sourceSets dirs from my Groovy project built by Gradle? I am looking for default gradle src and resources directories.
I need it to avoid hardcoding a resources directory in my project but use the default Groovy plugin resource directory (resources/main).
You shouldn't mix up your production code with your test sources and your test resources. I would suggest the following layout (the default of the groovy plugin) of your src directories in your project:
groovy production code in "src/main/groovy"
unit tests written in java or groovy in "src/test/groovy"
*.groovy resources for testing your DSL in "src/test/resources"
Now you can reference the .groovy dsl test files from your tests via
URL url = this.getClass().getResource("/testDsl.groovy");
File testDslFile = new File(url.getFile());
Can you explain the use case for that? within your gradle build you can access the groovy sourceSets dirs introduced by Gradles groovy plugin like this:
apply plugin:'groovy'
task printGroovySourceDirs << {
sourceSets.main.groovy.srcDirs.each{
println it.absolutePath
}
}