spock

Output unit testing results on console using spock junit testing and gradle build system

江枫思渺然 提交于 2019-12-01 04:03:46
问题 GNU Emacs 24.3.1 Gradle 1.12 spock-core.0.7 Hello, I am doing unit testing with spock framework using the gradle build system. When I run my tests gradle test I just see a message like this: * What went wrong: Execution failed for task ':test'. > There were failing tests. See the report at: file:///home/projs/gradleTest/build/reports/tests/index.html Then I have to go and check the xml file to see what exception has been thrown Is there any option where I could see the exceptions in my

Verify Spock mock with specified timeout

人走茶凉 提交于 2019-12-01 01:54:42
问题 In Mockito there is option to verify if mock method has been called, and specify timeout for this verification ( VerificationWithTimeout ), for example: verify(mock, timeout(200).atLeastOnce()).baz(); It there any equivalent to such functionality in Spock? 回答1: I was trying to use PollingConditions to satisfy a similar scenario (which wasn't helpful), but instead found satisfaction in Spock's BlockingVariables. To verify that SomeService.method() is invoked at least once in function

Get Spring Boot management port at runtime when management.port=0

本秂侑毒 提交于 2019-11-30 23:05:37
I'm looking for advice on how to get the port that was assigned to the embedded tomcat that is serving the actuator endpoint when setting management.port property to 0 in integration tests. Im using Spring Boot 1.3.2 with the following application.yml configuration: server.port: 8080 server.contextPath: /my-app-context-path management.port: 8081 management.context-path: /manage ... my integration tests are then annotated with @WebIntegrationTest , setting the ports shown above to 0 @WebIntegrationTest({ "server.port=0", "management.port=0" }) and the following utility class should be used to

Grails Testing with Spock - Which Mocking Framework Select?

这一生的挚爱 提交于 2019-11-30 19:11:47
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 similar implementation of service method mocking. This one works: @TestFor(MyController) @Mock([MyDevice]

Get Spring Boot management port at runtime when management.port=0

不羁岁月 提交于 2019-11-30 18:13:08
问题 I'm looking for advice on how to get the port that was assigned to the embedded tomcat that is serving the actuator endpoint when setting management.port property to 0 in integration tests. Im using Spring Boot 1.3.2 with the following application.yml configuration: server.port: 8080 server.contextPath: /my-app-context-path management.port: 8081 management.context-path: /manage ... my integration tests are then annotated with @WebIntegrationTest , setting the ports shown above to 0

How to inject spring beans into spock test

久未见 提交于 2019-11-30 14:21:32
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 extends Specification { @Autowired BusinessObjectDao businessObjectDao def "business never set at least

Execute some action when Spock test fails

安稳与你 提交于 2019-11-30 08:31:43
问题 I'd like to execute some action when Spock test fails. Specifically, take a screenshot. Is it possible? How to do it? 回答1: Create a listener class class ExampleListener extends AbstractRunListener { def void error(ErrorInfo error) { println "Actual on error logic" } } then add it to each specification using implementation of IGlobalExtension that is executed for each Spec class GlobalSpecExtension implements IGlobalExtension { @Override void visitSpec(SpecInfo specInfo) { specInfo.addListener

Running spock unit tests with Maven

微笑、不失礼 提交于 2019-11-30 08:24:34
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 : <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi

How to create Spock mocks outside of a specification class?

半腔热情 提交于 2019-11-30 07:25:45
问题 We combine Spock tests with Spring's @ContextConfiguration so we can build beans in a spring context and then use Spock for the actual testing. We would like to inject spock mocks into our spring beans. For Mockito there is an extension which allows you to do things like: <mockito:mock id="accountService" class="org.kubek2k.account.DefaultAccountService" /> and then reference this mock to other spring beans. There seems to be no such extension for Spock. Then again building this is probably

Learning GEB and Spock

自古美人都是妖i 提交于 2019-11-30 07:12:05
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. Arun Manivannan 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 you might want to consider Groovy in Action . While Java is not needed to pick up Groovy, If