new to spock - spring data database testing example

356 views
Skip to first unread message

Christopher Smith

unread,
Mar 5, 2015, 7:13:01 PM3/5/15
to spockfr...@googlegroups.com
Team,

I am trying to find the best way to test database access with spock with maven and spring.

I have DataAccess components (jdbc template ) and would like to make assertions on this component with spock.

I am new to this and I am looking for the best testing pattern to use.


I do not want to embed raw sql in the tests as this logic is already wrapped in my project.

In addition, it would be helpful to have a fully working maven web project with test configuration setup

I have also tried to follow this pattern here.




Test code I have tried, but I get compilation errors

[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.5:testCompile (default) on project geb-maven-example: startup failed:
[ERROR] /D:/development/workspace/gebmaven/src/test/groovy/DataAccessSpec.groovy: 20: expecting '}', found ':' @ line 20, column 53.
[ERROR] ku MWFP and customerclass RFG":


@ContextConfiguration("classpath:applicationContext.xml")

class DataAccessSpec extends Specification {

                // this is a JAVA data access component object from the web project
@Autowired
CopsPartsInfoBatchDAO copsPartsInfoBatchDAO
    def "find if a part exists" () {

given "a part with sku MWFP and customerclass RFG":
                // this is a JAVA object from the web project
def part = new CopsPartsInfo

String partNumber = "MWFP"
String customerClass = "RFG"
part.setSku(partNumber)
part.setExpandedsku(partNumber)
part.setPartnumber(partNumber)
part.setCustomerClass(customerClass)

when "checking if this part exists":
doesExist = copsPartsInfoBatchDAO.exists(part)
then: "this part must exist"
doesExist == true
}

}


rfle...@netflix.com

unread,
Mar 5, 2015, 8:42:50 PM3/5/15
to spockfr...@googlegroups.com
You have your block descriptor strings before the colon instead of after.

e.g. change

    given "a part with sku MWFP and customerclass RFG":

to

    given: "a part with sku MWFP and customerclass RFG"

J. David Beutel

unread,
Mar 5, 2015, 9:57:45 PM3/5/15
to spockfr...@googlegroups.com
I think the colon needs to come immediately after the given and when labels.

Cheers,
11011011


On 2015-03-05 14:00 , Christopher Smith wrote:

Christopher Smith

unread,
Mar 5, 2015, 10:40:11 PM3/5/15
to spockfr...@googlegroups.com
thanks gentlemen
Reply all
Reply to author
Forward
0 new messages