spock

Grails Spock integration test redirectedUrl different between localhost test-app and build server test-app

余生长醉 提交于 2019-12-13 00:56:27
问题 I have a Spock integration test that looks something like this: class PriceTierControllerIntegrationSpec extends IntegrationSpec { PriceTierController controller def setup() { controller = new PriceTierController() } def "applyDiscount() method will redirect user to success view"() { when: controller.applyDiscount() then: controller.response.redirectedUrl == '/priceTier/success' } Then in the controller, the logic is simply: class PriceTierController { def applyDiscount() { redirect action:

Problems casting a null object with Spock

谁说我不能喝 提交于 2019-12-13 00:17:56
问题 I have a Spock test that fails over two Mac OS X Lion machines, but works over other Linux machines and the Spock Web Console. I found another related question: Why I get a cannot cast object 'null' error, when testing my controller? I'm using Grails 2.0.0 and Spock 0.6. Any suggestions? Seems to be a bug def "casting null object"() { expect: null as BigDecimal == null } | Failure: casting null object(com.arturoherrero.MySpec) | org.codehaus.groovy.runtime.typehandling.GroovyCastException:

REST-assured with Spock and Groovy [closed]

旧巷老猫 提交于 2019-12-12 16:23:30
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am new to Spock and would like to write tests for a REST interface with Spock and REST-assured. Knowing REST-assurend in conjunction with Java I would like how to use REST-assured with Spock. Can anyone provide an example for this? 回答1: REST-Assured's DSL seems at odds with Spock's DSL. Potential solutions are

grails unit test + Thread

我怕爱的太早我们不能终老 提交于 2019-12-12 15:08:00
问题 I having a grails function, where I am using a separate Thread: def testFunction() { //..... Thread.start() { testService.somefunction() } //... } In the unit test, I'm mocking the service function like this: def "test testfunction" { //... 1 * testService.somefunction(_) //.. } However, I get the unmatched invocations error, because Spock didn't detect that the method was executed on the separate thread. 1 * testService.somefunction(_) (0 invocations) Unmatched invocations (ordered by

Test Groovy class that uses System.console()

允我心安 提交于 2019-12-12 12:13:38
问题 I have a groovy script that asks some questions from the user via a java.io.console object using the readline method. In addition, I use it to ask for a password (for setting up HTTPS). How might I use Spock to Unit Test this code? Currently it complains that the object is a Java final object and can not be tested. Obviously, I'm not the first one trying this, so thought I would ask. A sketch of the code would look something like: class MyClass { def cons MyClass() { cons = System.console() }

IntelliJ + Groovy + Spock

两盒软妹~` 提交于 2019-12-12 08:05:35
问题 I have been trying to create a Groovy project with Spock testing in IntelliJ IDEA. Here are steps that I followed: Created Groovy project and added Maven support. Added Spock dependencies and plugin. I am using POM very similar to this one: https://github.com/mariuszs/java-spock-test-sample/blob/master/pom.xml Due to conflicting Groovy dependency I removed Groovy 2.2 library from the Module Settings->Libraries. This allowed me to run tests. I created a Groovy class in "src/main".. but I get

Predefined mock response in Spock

让人想犯罪 __ 提交于 2019-12-12 06:28:15
问题 I'm new to Spock and this question refers to the example on page 178 of Java Testing with Spock. The class under test is the Basket class for a shopping application, and the method of this class being tested is canShipCompletely() public class Basket { private WarehouseIneventory warehouseInventory; private ShippingCalculator shippingCalculator; protected Map<Product, Integer> contents = new HashMap<>(); ... public void addProduct(Product product) { addProduct(product, 1); } public void

Using Spock Data Tables to Test Geb Page Objects

 ̄綄美尐妖づ 提交于 2019-12-12 04:19:42
问题 Full Disclosure: I'm very new to both Geb and Spock. As part of a test suite I'm working on, we have to test run the same test on several page elements. I would love to be able to abstract this behavior using a Spock data-table. However, when I do this, Geb complains that it doesn't recognize the page property. Here is a bare-bones example of what I'm talking about: when: textBox = value submit() then:"value is updated" at SuccessPage textBox == value where: textBox | value box1 | val1 box2 |

Browser Restart Using Geb & Spock within same test

。_饼干妹妹 提交于 2019-12-12 03:58:04
问题 I would like to be able to restart my browser session mid test using Geb and Spock Framework. I no howto close the browser and update after test compltion etc, but when i close during the test and try and re use the browser object i get a session error thrown by selenium. Below is the base outline i am trying to execute. NB never allows me to navigate to the new StoreHome and if i try and use just Browser i get error thrown. @Category(High.class) def "TC1: Verify Browser Restart"() { when:

Spock: How to run a set of methods as a single test repeatedly?

泄露秘密 提交于 2019-12-12 03:37:14
问题 I have a test case like below: def "Go to home page and click login button and go to login page" { } def "Input user ID and password and click login" { when: code.... then: code.... where: param1 << [ID1,ID2,ID3] param2 << [password1,password2,password3] } The test consists of two defs. I want to repeat the whole process with different ID and Password. How I can do that? For example: - First execute def "Go to home page and click login button and go to login page" - Than execute def "Input