spock

Spock with Mockito testing Kotlin classes

老子叫甜甜 提交于 2019-12-05 14:48:20
I have some tests written in Spock which covers my Java code. Now I migrate to Kotlin and the problem is i cannot mock final classes so i decide to use Mockito plugin described here: https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2#unmockable The question is do I need to replace every '_' '>>' with Mockitos' any(), anyString(), when(), then() etc? I tried to just mock final classes using Mockito but it seems not work. If i have to replace what the advantage is for using Spock testing framework in this case? Maybe i should remove it and stay with Mockito only? I do not use

spring boot 1.4, spock and application.properties

℡╲_俬逩灬. 提交于 2019-12-05 10:35:35
I am trying to write some tests for my Spring Boot 1.4.0 with Spock and my application-test-properties file is not being picked up. I have this in my gradle: dependencies { compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.springframework.boot:spring-boot-starter-security') compile('org.springframework.boot:spring-boot-starter-web') compile 'org.codehaus.groovy:groovy-all:2.4.1' testCompile('org.springframework.boot:spring-boot-starter-test') testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { } Then I have this in /src/test/groovy/resources: # JWT Key

Intelli-J can't run spock tests? (Unable to attach test reporter…)

不想你离开。 提交于 2019-12-05 07:15:07
I'm trying to use the grails spock plugin with 1.3.7. I can run tests from the terminal via grails test-app :spock , but when I try to run ControllerSpec tests from within Intelli-J, I get unable to attach test reporter to test framework or test framework quit unexpectedly . Has anyone run grails spock test successfully through Intelli-J? Yes I have and I have no problems with it. The only thing to remember is that when you right-click your Spec class, to select the right intelliJ runner. So: Right click class Run Select the jUnit icon, NOT the grails icon When I run into this error message (.

Injecting a mock service into a domain class for a Grails unit test?

▼魔方 西西 提交于 2019-12-05 04:49:25
I am writing some Spock spec based unit tests under Grails 2.1.1. I'm having trouble getting springSecurityService injected into my domain object that is used by my unit. This is what I have so far, @Mock([SecUser]) @TestFor(FooService) class FooServiceSpec extends Specification { def "test some stuff"() { given: def mockSecUserService = Mock(SecUserService) mockSecUserService.emailValid(_) >> { true } mockSecUserService.checkUsername(_) >> { null } service.secUserService = mockSecUserService def mockSpringSecurityService = Mock(SpringSecurityService) mockSpringSecurityService.encodePassword(_

How do you get the sessionFactory in a Grails Geb/Spock test case?

微笑、不失礼 提交于 2019-12-05 02:24:17
问题 I think I need to flush the hibernate session in a GebSpec test, and so I want to get the sessionFactory. It looks like it should be injected but when I do something like this:- class MySpec extends GebSpec { def sessionFactory ... def "test session"(){ ....do some setup then: assert sessionFactory != null } it fails with sessionFactory being null. 回答1: The short answer to my question is - why do you want to do that, it's a functional test and it may be remote from the running apps JVM. The

Debugging Java code tested with Spock and JMockit

陌路散爱 提交于 2019-12-04 18:18:01
I'm using Spock to write tests for a Java application. The test includes a JMockit MockUp for the class. When debugging a test (using IntelliJ) I would like to be able to step into the Java code. I realize using F5 to step into the code won't work, because of all the Groovy magic with reflection that goes on. Unfortunately, even if I set a breakpoint in the Java code, it still will not be hit, even though it runs through the code. Here is the code to test: public class TestClass { private static void initializeProperties() { // Code that will not run during test } public static boolean

Groovy单元测试框架spock数据驱动Demo

风格不统一 提交于 2019-12-04 18:07:27
spock是一款全能型的单元测试框架。 上次文章分享了spock框架的基础功能的使用,在此基础上,我根据自己写的Groovy的封装方法、数据驱动以及一些Groovy的高级语法做了一些尝试。发现还是有一点点问题,不知道是不是因为我本身是Java和Groovy混编的项目导致的,不过也都有了解决方案。 分享代码,供各位参考: package com.FunTester.spock.pratice import com.fun.config.PropertyUtils import com.fun.frame.SourceCode import org.slf4j.Logger import spock.lang.Shared import spock.lang.Specification import static com.fun.config.Constant.EMPTY import static com.fun.config.Constant.getLongFile import static com.fun.frame.Output.output import static com.fun.frame.SourceCode.* class Test02 extends Specification { @Shared def properties = PropertyUtils

Why can test private methods/fields in Spock without problems?

折月煮酒 提交于 2019-12-04 15:18:45
问题 package com.example.dev; public class AClass { private Integer a =10; ...//other code } and when I try to access a in my Spock method: package com.example.dev; def 'test a'() { AClass aClassVar = new AClass() aClassVar.a = new Integer(100); ...//other testing stuff } It works fine. Why this happens? Is Spock use reflection for accessing the private fields? Or my encapsulation in not written well? 回答1: Spock isn't guilty, it's groovy itself, see: Private method in groovy is not private. While

Unable to mock Grails Service method when unit testing Controller - MissingMethodException

[亡魂溺海] 提交于 2019-12-04 09:31:54
Am getting the following error message when testing the controller - see below for code. How can I correct this? When I invoke the service method from the controller (run-app) and it works fine. Exception: groovy.lang.MissingMethodException: No signature of method: grails.test.GrailsMock.isOk() is applicable for argument types: (java.lang.String) values: [H] at ...VControllerSpec.test something(VControllerSpec.groovy:) class: VControllerSpec import grails.test.mixin.TestFor import spock.lang.Specification @TestFor(VController) @Mock(VService) class VControllerSpec extends Specification { void

Is it possible to log spock feature method names and clause labels?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 08:30:55
I'd like to be able to log the spock feature names and clause labels when running some automated tests. This would help with debugging test issues when using a headless browser for automation, specifically phantomjs. Reason being, phantomjs does not always behave the same way as when using the chrome WebDriver. It would also be nice to have if this is even possible. def "Login logout test"(){ given: "Go to login page" ... when: "Submit username and password" ... then: "Dashboard page displayed" ... when: "logout" ... then: "Returned to login page" ... } For example, It would be cool if I could