spock

Mocked instance of final class in Spock behaves differently in test and dev code

匆匆过客 提交于 2020-06-09 04:12:53
问题 In my JavaFX application I am using Spock and Groovy for testing. I have dedicated WebBrowserController for taking care of my JavafX WebView component. I wanted to test some functionalities that depend on current Location and Document of the WebView . Relevant part of WebBrowserController: public WebEngine getEngine() { return panel.getWebView().getEngine(); } This is how I create an instance of WebBrowserController for my tests. Notice the GroovyMock I used there - ordinary Mock(...) does

Mocking of concrete class failing with Spock 2.0

陌路散爱 提交于 2020-06-01 05:05:46
问题 Mocking of external concrete class fails with the below mentioned error. java.lang.AbstractMethodError: Receiver class me.spike.LibraryTest does not define or inherit an implementation of the resolved method 'abstract java.lang.Object getProperty(java.lang.String)' of interface groovy.lang.GroovyObject. I've tried adding cglibs-nodep and objenesis but was not successful in getting to mock the concrete class. The repository mentioned here has a failing test. The test itself nonsensical. The

Mocking of concrete class failing with Spock 2.0

↘锁芯ラ 提交于 2020-06-01 05:03:12
问题 Mocking of external concrete class fails with the below mentioned error. java.lang.AbstractMethodError: Receiver class me.spike.LibraryTest does not define or inherit an implementation of the resolved method 'abstract java.lang.Object getProperty(java.lang.String)' of interface groovy.lang.GroovyObject. I've tried adding cglibs-nodep and objenesis but was not successful in getting to mock the concrete class. The repository mentioned here has a failing test. The test itself nonsensical. The

Find the outcome/status of a test in Specification.cleanup()

岁酱吖の 提交于 2020-05-31 04:06:06
问题 It seems a reasonable thing to want to do... e.g. log something when a test fails, and not if it doesn't. I've found this, for example, from 2013... there were no both simple and effective answers at the time. What about now? I hoped a suitable property/method might be found in org.spockframework.runtime.SpecificationContext ... or maybe org.spockframework.runtime.model.SpecInfo ... but I can't see anything. later To answer the question of the sort of thing I might want to do: in fact my

Maven surefire plugin not running tests after migrating from Spock 1.2 to 2.0-M2

送分小仙女□ 提交于 2020-05-30 11:44:38
问题 Working setup - Spock older version - 1.2-groovy-2.4 jdk version - 8 Maven surefire plugin version - 2.22.0 Maven version - 3.5.0 Migrated setup - Spock version - 2.0-M2-groovy-2.5 jdk version - 11 Maven surefire plugin version - 3.0.0-M4 Maven version - 3.6.3 MCVE - https://github.com/ajaydivakaran/spock_spike The intent of upgrading Spock was to make it compatible with jdk 11. The test class files are present in the target/test-classes folder but are not run. 回答1: Variant A: JUnit 4 + Spock

Maven surefire plugin not running tests after migrating from Spock 1.2 to 2.0-M2

扶醉桌前 提交于 2020-05-30 11:42:49
问题 Working setup - Spock older version - 1.2-groovy-2.4 jdk version - 8 Maven surefire plugin version - 2.22.0 Maven version - 3.5.0 Migrated setup - Spock version - 2.0-M2-groovy-2.5 jdk version - 11 Maven surefire plugin version - 3.0.0-M4 Maven version - 3.6.3 MCVE - https://github.com/ajaydivakaran/spock_spike The intent of upgrading Spock was to make it compatible with jdk 11. The test class files are present in the target/test-classes folder but are not run. 回答1: Variant A: JUnit 4 + Spock

Spock Unroll seems to print something odd with boolean parameter

风格不统一 提交于 2020-05-17 05:49:09
问题 I just put this test method together: @Unroll def 'super start edit should be called if cell is not empty'( boolean empty ){ given: DueDateEditor editor = GroovySpy( DueDateEditor ){ isEmpty() >> empty } when: editor.startEdit() then: if( empty){ 0 * editor.callSuperStartEdit() } else { 1 * editor.callSuperStartEdit() } where: empty | _ true | _ false | _ } ... it works OK in terms of the two tests passing... but when you make it fail it's very odd: the output if the parameter empty is false

Spock Test Failing with MissingPropertyException

泪湿孤枕 提交于 2020-05-15 08:47:10
问题 I have a simple class that builds a RequestMessage based on a simple rule. If MessageMetadata is found in the database, the message is built using that metadata. Otherwise, the message is built using a service that provides the metadata. Here is the class along with a Spock test. The test fails with a MissingPropertyException , saying it cannot find the RequestMessage created using the service. class MessageService{ MessageBuilder messageBuilder; MessageRepository messageRepository;

How to test ListenableFuture Callbacks in spock

别说谁变了你拦得住时间么 提交于 2020-05-09 10:49:05
问题 I asked a question a few days ago regarding stubbing the future response from the kafka.send() method. this was answered and explained correctly by @kriegaex here Though I faced another issue, on how can i test the onSuccess and onFailure callbacks of this future response. here's the code under testing. import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.support.SendResult; import org.springframework.util.concurrent.ListenableFuture; import org

使用Groovy进行Java的单元测试

▼魔方 西西 提交于 2020-04-26 06:06:47
为什么用Groovy写单元测试 它与Java 平台无缝的集成,它是基于 Java 的语言(不像其他语言,是对 JRE 的替代,因此可能基于旧版的处理器),对于 Java 开发人员来说,Groovy 意味着一条短得让人难以置信的学习曲线。而且一旦将这条学习曲线拉直,Groovy 就能提供一个无与伦比的快速开发平台。 从这个角度来说,Groovy 成功的秘密,在于它的语法 就是 Java 语法,但是规则更少。例如,Groovy 不要求使用分号,变量类型和访问修饰符也是可选的。而且,Groovy 利用了标准的 Java 库,这些都是您已经很熟悉的,包括 Collections 和 File/IO 。而且,您还可以利用任何 Groovy 提供的 Java 库,包括 JUnit。 事实上,令人放松的类 Java 语法、对标准 Java 库的重用以及快捷的生成-运行周期,这些都使 Groovy 成为快速开发单元测试的理想替代品。 如何使用Groovy进行Mock测试 用Groovy进行Mock要比JMockit之类的简单很多,下面举例还演示如何使用 待测试类 折叠源码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41