Started playing with grails and I want to evaluate GORM, so I created a domain class using Spring Tool Suite: Client with name, vatNumber, and regNumber and the test class was created automatically.
The code for unit test I added is :
package pilot1
import grails.test.*
class ClientTests extends GrailsUnitTestCase {
protected void setUp() {
super.setUp()
}
protected void tearDown() {
super.tearDown()
}
void testSomething() {
def instances = []
def myTestDomain = mockDomain(Client, instances)
def client = new Client(name:"Test",vatNumber:"323",regNumber:"343")
client.id =1;
assertEquals client.name, "Test"
client.save();
def res = Client.findByName("Test")
println instances
println res
//assertEquals 1, instances.size()
}
}
The results are [] and null! What did I do wrong?
Also, I would like also to see the SQL generated by GORM (Hibernate) behind the scenes. Any idea how I might do that in Grails ?
http://www.ibm.com/developerworks/java/library/j-grails10148/index.html
“As I mentioned earlier, Grails supports two basic types of tests: unit and integration. There’s no syntactical difference between the two — both are written as a GroovyTestCase using the same assertions. The difference is the semantics. A unit test is meant to test the class in isolation, whereas the integration test allows you to test the class in a full, running environment.
Quite frankly, if you want to write all of your Grails tests as integration tests, that’s just fine with me. All of the Grails create-* commands generate corresponding integration tests, so most folks simply use what is already there. As you’ll see in just a moment, most of the things you want to test require the full environment to be up and running anyway, so integration tests are a pretty good default.”