spock

How to test a Grails Service that utilizes a criteria query (with spock)?

こ雲淡風輕ζ 提交于 2019-11-30 06:59:33
I am trying to test a simple service method. That method mainly just returns the results of a criteria query for which I want to test if it returns the one result or not (depending on what is queried for). The problem is, that I am unaware of how to right the corresponding test correctly. I am trying to accomplish it via spock, but doing the same with any other way of testing also fails. Can one tell me how to amend the test in order to make it work for the task at hand? (BTW I'd like to keep it a unit test, if possible.) The EventService Method public HashSet<Event> listEventsForDate(Date

How to find port of Spring Boot container when running a spock test using property server.port=0

本秂侑毒 提交于 2019-11-30 05:19:39
Given this entry in application.properties : server.port=0 which causes Spring Boot to chose a random available port, and testing a spring boot web application using spock, how can the spock code know which port to hit? Normal injection like this: @Value("${local.server.port}") int port; doesn't work with spock. Bohemian You can find the port using this code: int port = context.embeddedServletContainer.port Which for those interested in the java equivalent is: int port = ((TomcatEmbeddedServletContainer)((AnnotationConfigEmbeddedWebApplicationContext)context).getEmbeddedServletContainer())

Run a specific test in a single test class with Spock and Maven

自作多情 提交于 2019-11-30 05:07:03
问题 I am using Spock framework for testing (1.0-groovy-2.4 release). Junit offers this option to run a specific test using the command line (with Maven): mvn -Dtest=TestCircle#mytest test Question : How can I do this with Spock? This version has a dependency on Junit 4.12 , it is stated in Junit documentation that this feature is supported only for Junit 4.x , basically Spock should propose something similar. 回答1: After a further investigation, the answer is most probably: No, you can't invoke

Grails Testing with Spock - Which Mocking Framework Select?

橙三吉。 提交于 2019-11-30 04:30:12
问题 I have more general question. Which framework or implementation I should use for mocking in Grails 2.x when using Spock? I know tons of mocking style: leverage Groovy metaClass, Grails mockFor(), Groovy Mock(), Groovy closure style, etc. Each of them has its own advantages and disadvantages. But what I don't understand is that some mocking style works in certain occasions which I cannot determine (i.e. mockFor() works for certain implementation and not for the others). Currently I have two

Integrate Spock's test with Sonar

与世无争的帅哥 提交于 2019-11-30 03:48:31
问题 I use spock to write test case and jenkins to run and publish my test cases. I was able to get the code coverage reported but sonar shows me only Java Unit test cases; the groovy test cases are totally missing The following pom.xml is used as reference https://github.com/kkapelon/java-testing-with-spock/blob/master/chapter7/spring-standalone-swing/pom.xml would anyone please know what I am missing ? 回答1: Install the Groovy plugin in Sonar. Login as admin/admin and go to the administration

How to inject spring beans into spock test

懵懂的女人 提交于 2019-11-29 20:39:30
问题 I am new to spock. I am trying to write a spock unit test against a standalone java app that uses JDK 1.7, Spring 3.1, Groovy 1.8.6, Spock 0.6, Maven 3.0.4. A basic hello world spock test is working. However when I try to test spring beans, I find that they are not getting injected. I use the approach mentioned here. businessObjectDao is null within when block. How do I get this working? @ContextConfiguration(locations = "classpath*:test-appContext.xml") class BusinessObjectPersistenceTest

Spock Stepwise - Keep running testsuite after single failure

五迷三道 提交于 2019-11-29 12:54:51
When using the Spock @Stepwise annotation, is there any way to configure it to not fail the entire testsuite after a single test fails? Decided to just create a new extension called @StepThrough. All I needed to do was subclass StepwiseExtension and take out the line of code that was failing the entire test suite. Pasted code below... StepThrough.groovy package com.test.SpockExtensions import org.spockframework.runtime.extension.ExtensionAnnotation import java.lang.annotation.ElementType import java.lang.annotation.Retention import java.lang.annotation.RetentionPolicy import java.lang

Running spock unit tests with Maven

回眸只為那壹抹淺笑 提交于 2019-11-29 11:11:03
问题 On a previous project I used the Spock testing framework to unit test my Java code. I found this really productive so I am trying to add Spock tests to my current project which uses Maven as its build tool (The previous project used Gradle). While I can get Maven to compile my Spock tests (using groovy-eclipse-compiler ), I am unable to get Maven to run the tests. I've made a simple example to demonstrate my problem with 2 files: pom.xml src/test/java/ASpec.groovy Contents of pom.xml :

How to integration test auto configuration for a custom Spring Boot style starter library?

心已入冬 提交于 2019-11-29 10:59:16
I am writing a library to provide some functionality that is shared between multiple different Spring Boot applications that I work with. I would like to do something similar to the auto-configuration that is provided by the many Spring Boot starter libraries exist. That, or some other simple declarative way to integrate my library with the ApplicationContext of the apps using it. I have found some resources explaining how auto configuration works. I can figure out the above problem. However, I have not been able to find any good examples of how I can test as part of my library's test suite

Learning GEB and Spock

我的梦境 提交于 2019-11-29 09:00:20
问题 I am a manual tester trying to learn GEB and Spock. To learn these do I have to have prior knowledge of java or groovy? I have been reading the book of GEB, What are the prerequisites, books or learning resources? Please help. Thanks. 回答1: I tried compiling some essentials and some 'good-to-haves' that I found very helpful when I picked up Geb. Some Groovy Magic. Most of all that you need to learn Groovy is covered in this manual but for obvious reasons if you get obsessed with the language