Reputation: 9306
I'm writing a unit test for my domain class but I get a NPE when I tried to run the following test:
def st
void setUp(){
super.setUp()
mockForConstraintsTests(Student)
st=new Student(firstName:"Feras",lastName:"Ahmad")
}
void testMinSize() {
st.firstName="J"
assertFalse st.validate();
}
I got the NPE on the first line of testMinSize method. what is wrong with that? I think setUp method is called before every test. Is this true?
Thanks,
Upvotes: 1
Views: 128
Reputation: 7048
Maybe you could try the @Before
annotation
@Before
void setUp(){
super.setUp()
print "I'm there"
mockForConstraintsTests(Student)
st=new Student(firstName:"Feras",lastName:"Ahmad")
}
The documentation puts sometime the annotation, sometime not. Maybe it depends on the grails/JUnit version.
Upvotes: 1