spock

Installing Grails Spock Plugin in 2.0.0M1

泪湿孤枕 提交于 2019-12-10 16:19:15
问题 I'm kicking the tires on Grails 2.0.0M1 and Springsource Tool Suite 2.7.1, but I'm having problems installing the spock plugin. When I run "grails install-plugin spock 0.6-groovy-1.8-SNAPSHOT" I get: | Downloading: spock-0.6-groovy-1.8-SNAPSHOT.pom :: problems summary :: :::: ERRORS grailsCentral: bad organisation found in http://svn.codehaus.org/grails-plugins/grails-spock/tags/RELEASE_0_6-groovy-1_8-SNAPSHOT/spock-0.6-groovy-1.8-SNAPSHOT.pom: expected='org.grails.plugins' found='org

Test Spring MVC controller with @PreAuthorize giving 403-Access denied

こ雲淡風輕ζ 提交于 2019-12-10 15:39:51
问题 trying to write some integration test with Spock framework for my controller that has @PreAuthorize annotation on it. When I run the app, this tag is working like a charm. However, when I run integration test I get 403. My SecurityConfig.java : @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter{ @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests()

Class cannot resolve module as content unless @Stepwise used

独自空忆成欢 提交于 2019-12-10 15:22:52
问题 I have a Spock class, that when run as a test suite, throws Unable to resolve iconRow as content for geb.Page, or as a property on its Navigator context. Is iconRow a class you forgot to import? unless I annotate my class with @Stepwise. However, I really don't want the test execution to stop on the first failure, which @Stepwise does. I've tried writing (copy and pasting) my own extension using this post, but I still get these errors. It is using my extension, as I added some logging

Spock + Drools Testing

▼魔方 西西 提交于 2019-12-10 14:13:01
问题 I have a question regarding SPOCK + Drools testing. Here's the thing, KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(); That line of code works absolutely fine,inside a JUnit test case. It doesn't inside SPOCK. I get the following exception, java.lang.NoClassDefFoundError: com/sun/tools/xjc/Options at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46) at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33) Caused by: java.lang

How to run more than one test but not all the tests in GEB using Gradle?

旧街凉风 提交于 2019-12-10 12:13:42
问题 I am running gradle to run the tests from Windows command line. What I do to run a single test is: gradlew.bat chromeTest -DchromeTest.single=test1Spec or for all the tests: gradlew.bat chromeTest If I try to run only two test classes like this: gradlew.bat chromeTest -DchromeTest=test1Spec,test2Spec--info then gradle starts to run all the tests. What I need: is to run only 2 or 3 Groovy classes. To be specific, neither one nor all. Any help would be really beneficial! Sorry, for reposting

Spock mock verify returns 0 invocations

百般思念 提交于 2019-12-10 11:25:09
问题 Im working on a Spring Boot java service that contains a Camel Processor class as follows: public class MyProc implements Processor { @Autowired private LogService logService; public void process(Exchange e) { // exchange object processing logService.update(e) } } And I have the following Spock test: class MyProcTest extends Specification { @Shared def logService = Mock(LogService) @Shared def proc = new MyProc() def ctx = new DefaultCamelContext() def exch = new DefaultExchange(ctx) void

Spock How to mock Autowired class' function call within a method

主宰稳场 提交于 2019-12-10 10:45:28
问题 I have a class that I want to test in that looks like this: package com.something; import org.springframework.beans.factory.annotation.Autowired; public class ClassToTest implements InterfaceToTest{ @Autowired AnotherService serviceA; @Override public List<String> methodToTest(List<String> randomVar){ ... String stringA = serviceA.someFunction(randomVar); ... } } How can I mock the results from the call to serviceA.someFunction(randomVar) to return any String of my choice when testing with

Grails IntegrationSpec IllegalStateException

笑着哭i 提交于 2019-12-10 10:29:58
问题 After upgrading to 2.4.2 from 2.4.0, I am getting an error when I run my integration tests. It shows that the tests passed, however I am getting an IllegalStateException. Failure: | massemailsystem.UserInformationIntegrationSpec | java.lang.IllegalStateException: Could not find ApplicationContext, configure Grails correctly first at grails.util.Holders.getApplicationContext(Holders.java:97) at grails.test.spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:41) I tried

How to set final field in Groovy

只谈情不闲聊 提交于 2019-12-10 09:46:42
问题 I have a java class which i test in groovy/spock. The java class has a final field: private static final log = Logger.getLogger(...) I want to test if a method uses this logger, preferably using a mock. The problem is that this field is final so I can't just set it. I know that there are workarounds like: modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); but these are awful hacks. Is there a more groovy way to do this? 回答1: You could try testing logging by configuring your

Using spock data table for filling objects

不问归期 提交于 2019-12-09 13:28:11
问题 I am using Spock for the first time. Since we are using a complex domain-model it would be handy to have a mechanism, which allows me to create full objects from data given by spock tables. I do not want to give all values each time, I just want to set the values in defined in datable. So there should be defined default values somewhere. Yes, I know I could write on my own, but maybe there is an out-of-the-box solution. Example class A { String name int age } spock table id | givenA | ... 1 |