spock

How to setup and teardown functional test data in Geb grails

情到浓时终转凉″ 提交于 2019-12-14 03:45:42
问题 I have many working/passing functional geb/spock tests (each extending GebReportingSpec) that are testing a web application with test data all created from the BootStrap.groovy at the beginning of the functional test suite. I want to move the test data creation into startup() / teardown() methods within each Spec, well actually I wanted to have them inherit it from a base class but apparently the StepWise has issues with inheritance. So, at present each of my test spec classes look something

How can I search and return the values and pass it to the method from spock table

爷,独闯天下 提交于 2019-12-14 03:34:41
问题 Currently implementing GEB,Spock,Groovy. I come across the scenario like There is a set of data's in the spock table. I have to pass the modulename as a parameter, Search from the spock table then return two values user id and password. Below code is skeleton code My question is how to search module name based on parameter? How to return two data's ? Class Password_Collection extends Specification { def "Secure password for search and Data Driven"(String ModuleName) { expect: // Search based

groovy per instance metaClass method override doesnt work as expected in spock test

一笑奈何 提交于 2019-12-14 01:56:44
问题 having a problem I have a class with method called execute(). In some spock unit test i dummy out the execute method and give it a mock closure like this def setup () { rule = new DynamicRule () } def "test default execution " (){ given : "basic AORule " def mockres rule.metaClass.execute = {-> mockres = "did nothing"} //mock the action def res = rule.execute() expect : "execute should do nothing " mockres == "did nothing" } if i run this test it fails. in the idea editor it shows the mock

Spock: Reading Test Data from CSV File

浪子不回头ぞ 提交于 2019-12-14 01:14:10
问题 I'm trying to write an elegant Spock specification that will read a very large test data from CSV file without loading all the data into the memory. I'm looking for your feedback on how you might do it better than what I currently have here. Let's assume my simplified CSV file looks like the below:- 1,2 3,4 5,6 The assertion is "column 1" + 1 == "column 2" I'm using OpenCSV to do my CSV parsing simply because the actual CSV file contains strings with special characters like double quotes and

executeUpdate() not updating on grails spock-integration testing

泪湿孤枕 提交于 2019-12-13 23:02:01
问题 hi i am new to grails testing. Willing to do integration test as below but problem is that executeUpdate() seems not updating the value How to do integration testing for executeUpdate('update query goes here') ?? Please help suggest me Sample code is given for problem demo. Thanks in advance. def "for given merchantTier Id update merchantTier value"(){ setup: def merchantTier = new MerchantTier( value:1.11).save(flush: true) //it saves merchantTier when:"when update with setProperty" testData

How to run Geb TestCases from windows command line?

那年仲夏 提交于 2019-12-13 09:55:30
问题 I want to be able to run the geb testcases(SampleTestCase.groovy) from windows command line? I am having a hard time doing so, can anyone please help me out with this? Thanks 回答1: gradlew ''moduleName':test --tests *'fullSpecWithpackage' 来源: https://stackoverflow.com/questions/55324604/how-to-run-geb-testcases-from-windows-command-line

Why I get a cannot cast object 'null' error, when testing my controller?

爱⌒轻易说出口 提交于 2019-12-13 04:12:05
问题 I have a controller like this : def unCompletedTasks() { def user = User.get(springSecurityService.principal.id) def choice = params.managersProject params.max = Math.min(params.max ? params.int('max') : 10,100) def search = Tasks.createCriteria().list(max: params.max as Integer, offset: params.offset as Integer, order: params.order as String, sort : params.sort) { and { project { like('name',"${choice}") } eq('completed',false) lt('endDate',new Date().clearTime()) } } [tasksInstanceList :

How to mock Mono.create

隐身守侯 提交于 2019-12-13 03:58:21
问题 I'm using the spock framework and need to return a mocked Mono from a Mono.create(..) I've tried: GroovyMock(Mono) as well as GroovyMock(Mono, global:true) 1 * Mono.create(_ as MonoSink) >> Mono.just(returnedValue) But I get the message that there were too few assertions for the above code. Here is the actual Mono.create code Mono.create{ sink -> myAPISoap.getStuffAsync( username, password, info, { outputFuture -> try { sink.success(outputFuture.get()) } catch(Exception e){ sink.error(e) } }

How to have geb static content recognized form test script

允我心安 提交于 2019-12-13 03:52:10
问题 The example: Page Class Page TestPage extends Page{ static at = {blah blah....} static content = { someVar {$(By.id("someId"))} } } Script: class Test extends GebReportingSpec{ def "some Feature Methods"(){ when: def page1 = at TestPage page1.someVar.click() //In intellij "someVar" shows as unrecognized } } According to what I have read and researched, in the example above, someVar should autocomplete and be recognized, but it is not. the code still runs and works correctly but someVar still

Mocked java class in spock test is not being executed

穿精又带淫゛_ 提交于 2019-12-13 03:36:12
问题 I'm trying to use spock framework for unit testing some java class. The structure looks like this: com.myorg.requests (Class name: RequestProcessor ) com.myorg.query (Class name: DatabaseQuery ) The first class looks something like this: public class RequestProcessor { private String request; public RequestProcessor(String aRequest) { this.request = request; } public String processRequest() { String response ; //do something here try { if(condition meets) { response = executeRequest(); } }