i don't know whether use unit or integration tests wanting test in grails 2.2.3 application. want run tests against this:
@testfor(student) @mock(student) class studenttests { void testfoundstudent() { def s = student.findbyid(myid) assert s != null assert s.firstname = 'grant' assert s.lastname = 'mcconnaughey' } }
this going require use of our test database, make integration test? when run code unit test fails @ assert s != null
. means isn't using our database, because should find student id.
in grails unit test can test domain class interactions using gorm , behind scene grails use in-memory database(an implementation of concurrenthashmap) mimic behavior here. yes null because student not exist in in-memory database , need insert data first.
student.findorsavewhere (firstname: 'grant',lastname : 'mcconnaughey')
in example, if intention test existence of data need use integration test , connect database using datasource.groovy
, not idea unless have reason test data.
if trying test def s = student.findbyid(myid)
again not adding value grails dynamic finder , need trust framework using.
however, in general
unit tests typically run without presence of physical resources involve i/o such databases, socket connections or files link
i hope helps
Comments
Post a Comment