spock

Spock mocks showing up as nulls

早过忘川 提交于 2019-12-11 15:48:22
问题 Here is my main class: @Slf4j class ConsoleReaderWorker implements Runnable { ConsoleReader reader Writer writer RemoteCommandSelector commandSelector @Inject ConsoleReaderWorker(ConsoleReader reader, Writer writer, RemoteCommandSelector commandSelector) { super() this.reader = reader this.writer = writer this.commandSelector = commandSelector } @Override void run() { try { String line while ((line = reader.readLine()) != null) { commandSelector.select(line).execute(writer) writer.flush() } }

Selenium commands not working in Chrome web driver (working with firefox)

情到浓时终转凉″ 提交于 2019-12-11 15:37:53
问题 I'm writing integration/e2e tests and for some reason any selenium driver commands don't see to be working with chromedriver, but they are working flawlessly with firefox driver and the firefox headless driver. Commands tried: moveByOffset , and doubleClick Tried both Geb's Interact method interact { doubleClick(centerClickable) } and accessing the webdriver directly: def driver = browser.getDriver() Actions action = new Actions(driver) WebElement element= driver.findElement(By.className("vis

Spock: mocking/stubbing void method of final class

爷,独闯天下 提交于 2019-12-11 15:37:30
问题 The mocked class here is org.apache.lucene.document.TextField . setStringValue is void . My Specification looks like this... given: ... TextField textFieldMock = GroovyMock( TextField ) // textField is a field of the ConsoleHandler class, ch is a Spy of that class ch.textField = textFieldMock // same results with or without this line: textFieldMock.setStringValue( _ ) >> null // NB I explain about this line below: textFieldMock.getClass() >> Object.class the corresponding app code looks like

grails “test-app” fails for functional geb+spock test but “test-app -functional” is successfull

懵懂的女人 提交于 2019-12-11 14:41:50
问题 I have some problems regarding functional testing in Grails using GEB+Spock. If i run "test-app" it always fails, but if i run "test-app -integration" before "test-app" it works! The following test-sequence illustrates my problem: Run #1 grails> clean grails> test-app -functional ... Tests PASSED Run #2 grails> clean grails> test-app ... Tests FAILED Run #3 grails> clean grails> test-app -functional ... Test PASSED grails> test-app ... Test PASSED The tests that are failing are throwing "geb

Stubbing or mocking static methods in Java with Spock

前提是你 提交于 2019-12-11 14:32:32
问题 Is it possible to mock static methods in java with spock? I know it is possible to mock static groovy methods but can't get this working for Java methods. 回答1: No. You need PowerMockito for that. Refactor the class or alternatively wrap the static call in a protected method and stub it out as a spy. 来源: https://stackoverflow.com/questions/56870800/stubbing-or-mocking-static-methods-in-java-with-spock

Spock block mocks and where to wire them

雨燕双飞 提交于 2019-12-11 12:36:24
问题 I have seen Spock tests where mocks are wired up & configured in the given block (which is where it makes the most sense to me), as well as cases where the only way to get the test to pass required me to wire/configure the mocks inside the then block, which is just plain silly to me. An example of the latter is a question that I asked some time ago. So I ask: What determines where to actually wire/config a mock, either in given or in then ? I really hope the answer isn't just " keep playing

groovy spock mocking spring autowired beans

旧巷老猫 提交于 2019-12-11 11:25:02
问题 I have bean: @Service public class EQueueBookingService { @Autowired public EQueueBookingClient eQueueBookingClient; And I try to write some test for this bean EQueueBookingService using Spock. https://code.google.com/p/spock/wiki/SpockBasics My mock is class EQueueBookingServiceTest extends Specification { @Autowired EQueueBookingService testedService; EQueueBookingClient eQueueBookingClient = Mock(EQueueBookingClient); def setup() { testedService.eQueueBookingClient = eQueueBookingClient; }

Selenium 4 Java的最佳测试框架

孤人 提交于 2019-12-11 11:06:05
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 几十年来,Java一直是开发应用程序服务器端的首选编程语言。尽管JUnit一直在与开发人员一起帮助他们进行自动化的单元测试,但随着时间的推移和测试行业的发展,特别是伴随着自动化测试的兴起,已经开发了许多基于Java的开源框架,它们在验证和业务逻辑方面与JUnit有所不同。在这里,我将讨论用于使用Selenium WebDriver执行测试自动化的顶级Java测试框架,还将重点介绍这些顶级Java测试框架的优缺点和独到之处。 JUnit Junit是开发人员基于xUnit基础上开发的一个实用案例。其最初主要目的是使Java开发人员能够编写脚本并执行可重复的测试用例。它通常用于测试一小段代码。您还可以通过将JUnit与用于测试自动化的Selenium集成来执行网站的自动化测试。每当添加任何新代码需要发版时,都需要重新执行整个测试用例,并确保没有不影响原有功能。 有哪些先决条件? 该框架与Selenium WebDriver for Java高度兼容,因此,JUnit和Selenium WebDriver也是完全兼容的,作为某些先决条件,您需要 在工作项目中使用较新版本的JDK。 下载最新版本的JUnit并设置环境。 对面向对象的编程语言(Java)的应用程序开发有很好的使用经验。 使用JUnit的优缺点?

How to test Storm using Spock when emitting large output Tuples

无人久伴 提交于 2019-12-11 08:46:36
问题 So I have the following test: def "test execute(inputTuple) method emits an outputTuple containing a member ObjectType retrieved using the entity_id in inputTuple"() { given: Tuple inputTuple = Mock(Tuple); List<String> objectTypeIDsEmittedByPreviousBolt = new ArrayList<String>(); objectTypeIDsEmittedByPreviousBolt.add("member"); objectTypeIDsEmittedByPreviousBolt.add("1196"); 1 * inputTuple.getValues() >> objectTypeIDsEmittedByPreviousBolt; when: this.bolt.execute(inputTuple); then: 1 * this

log4j: how to get the last inserted log message?

China☆狼群 提交于 2019-12-11 07:44:52
问题 I wonder if there is way to retrieve the last inserted log to my log4j log file ? Also, I need it to be run while unit-testing on Spock. Thanks! 回答1: You can always write your own appender where log messages go through: Get live Log4J messages 来源: https://stackoverflow.com/questions/26533121/log4j-how-to-get-the-last-inserted-log-message