spock

Difficulty running grails tests in IntelliJ : Illegal use of nonvirtual function call

纵饮孤独 提交于 2019-12-09 11:46:15
问题 Lately I've been trying to run my spock tests in IntelliJ (which used to work beautifully and had great debugging / specific test re-running on failure features) and in the past few months I've began getting the following error: | Error Error executing script TestApp: (class: com/company/MyServiceSpec, method: super$2$oldImpl signature: (Ljava/lang/Object;)Ljava/lang/Object;) Illegal use of nonvirtual function call (Use --stacktrace to see the full trace) It's a spock test that runs just fine

Selecting specific tests to run in gradle

孤街浪徒 提交于 2019-12-09 08:40:46
问题 I'm trying to fix our messy failing test runs, and, unfortunately, I'm very new to gradle. We currently have testng, junit, and I'd like to add some spock tests to the mix as well. I'm not quite sure how gradle determines which tests to run when I type "gradle test". How can I prevent the testng &/or junit tests from running? How can I get gradle to start running my spock tests? 回答1: By default, the test task runs all JUnit tests it can find, which includes any Spock tests. To make it run

Is there any way to do mock argument capturing in Spock

微笑、不失礼 提交于 2019-12-09 05:01:05
问题 I have looked around and tried different things to no avail. The examples out there on the interwebs are few, and IMHO pretty simple. My use case: (the 'itocNetworkHandler' below is the mock) when: "we're doing stuff" StandardResponse response = cms.doCardStuff("123", "111", order) .... then: "we get proper calls and response object" 1 * cms.itocNetworkHandler.doNetworkCall( { it instanceof ReplacementRequestRecord }, StandardResponseRecord.class) >> record I would like to store away the

Asserting on a list of items in Spock

做~自己de王妃 提交于 2019-12-09 03:15:34
问题 Using Spock 0.7 with Grails 2.04. Trying to set up a testing environment. I need some help in regards to testing a list of objects. I have a list of location objects. I want to test a date on each of those objects. I am iterating over but not sure how to make the test fail if the dates are not equal. Is there a good way to test objects in a list? I have listed below my then block of code. then: weatherList != null weatherList.empty != null weatherList.size() == 3 weatherList.each { Calendar

Forcing Spring Boot to NOT use EmbeddedWebApplicationContext?

天涯浪子 提交于 2019-12-08 12:48:24
问题 I have a Spock test case where I want to load a Spring application. I have a very rudimentary Groovy class that is my config object: @Configuration @EnableAutoConfiguration class TestConfig { @Bean Map createSillyMsgMap() { ["sillyMsg" : "This is a silly message"] } public static void main(String[] args) { println "TestConfig.main(${args})" } } Obviously, this is isn't very useful, but it serves as an example. For convenience, I've also added the main method in that class. My test class just

How to test static java methods in groovy SPOCK framework?

假如想象 提交于 2019-12-08 09:50:10
问题 I am trying to test static java method in SPOCK groovy framework using Maven. Here is the java class public class DataController { private DataInterface userService; public void setUserService(DataInterface userService) { this.userService = userService; } public static int addNumber(){ int a = 10; int b = 20; return a+b; } } Here is the SPOCK test in groovy @PrepareForTest([DataController.class]) class BasicMockStaticTest extends Specification { @Rule PowerMockRule powerMockRule = new

Spock Mock not working for unit test

旧街凉风 提交于 2019-12-08 05:06:39
问题 I am getting weird results from a Spock unit test that I thought was being caused by a misuse of Groovy's TupleConstructor annotation. However, thanks to the help of another user, I see it is a problem with the way Spock is creating mocks. Although I have fixed the issue by replacing the injected mocks with real instances, I need to in fact get mocks working here. My main classes: @Canonical @TupleConstructor(callSuper = true) abstract class Vehicle { Long id } @Canonical @TupleConstructor

How to run spock test from command line?

旧巷老猫 提交于 2019-12-08 02:18:23
问题 I have checked this link: https://gist.github.com/ysb33r/5825457 It seems like that it can be run like this: groovyc *.groovy java -cp ~/.grapes/org.spockframework/spock-core/jars/spock-core-0.7-groovy-2.0.jar:$GROOVY_HOME/embeddable/groovy-all-2.1.4.jar:$GROOVY_HOME/lib/junit-4.11.jar:$GROOVY_HOME/lib/hamcrest-core-1.3.jar:.org.junit.runner.JUnitCore ExampleSpec And I have added all third part jars to CLASSPATH,so all imports from these libs found.But all my own classes can't be found,and

Extract specifications from Spock specs

北城余情 提交于 2019-12-07 16:48:14
问题 Is there a way to obtain specifications (filtering the code) from my Spock tests printed in a file? For example, for the following spec: class CarSpec extends IntegrationSpec { def 'it should not retrieve deleted cars'() { given: 'a car' def car = new Car(uniqueName: 'carName') car.save() when: 'I delete the car' car.delete() then: 'it shouldn't find me the car on the DB' Car.find { uniqueName == 'carName' } == null } } should print something like: CarSpec it should not retrieve deleted cars

Spock Mock not working for unit test

余生颓废 提交于 2019-12-07 15:54:26
I am getting weird results from a Spock unit test that I thought was being caused by a misuse of Groovy's TupleConstructor annotation. However, thanks to the help of another user, I see it is a problem with the way Spock is creating mocks. Although I have fixed the issue by replacing the injected mocks with real instances, I need to in fact get mocks working here. My main classes: @Canonical @TupleConstructor(callSuper = true) abstract class Vehicle { Long id } @Canonical @TupleConstructor(callSuper = true, includeSuperProperties = true) abstract class Foobaz extends Vehicle { String name