title: Unit testing for domain classes using Grails
body: <p>Currently searching for tutorials, explanations and examples.
  I've tried different examples and came up to different errors.
  My current error is :</p>
  
  <blockquote>
    <p>| Error Compilation error compiling [unit] tests: startup failed:</p>
  </blockquote>
  
  <p>and in my test reports. It outputs this :</p>
  
  <p><strong>Unit Test Results - Summary
  No tests executed.</strong></p>
  
  <p>My "UserSpec.groovy" code is this :</p>
  
  <pre><code>package newmyproject245
  
  import grails.test.mixin.*
  import spock.lang.Specification
  
  @TestFor(User)
  class UserSpec extends ConstraintSpecification {
  
      def setup() {
          Expectations.applyTo User
      }
  
      def cleanup() {
      }
  
      void testShouldDoNothing() {
          Expectations.applyTo User
  
          user."password is not blank"
          user."password is not nullable"
          user."name is not blank"
          user."name is not nullable"
      }
  
      void testEventNameConstraints() {
          Expectations.applyTo User
          def user = new User()
  
          user."name is not blank"
          user."name is not nullable"
      }
  }
  </code></pre>
  
  <p>Can anybody help. I'm new in grails.
  Thanks!</p>
  
  <p>Additional to the above problem,
  when I omitted the <strong>Contraints</strong> in class as shown :</p>
  
  <pre><code>class UserSpec extends Specification {
  </code></pre>
  
  <p>I came up to this error :</p>
  
  <blockquote>
    <p>| Running 1 unit test... 1 of 1 
    | Failure: initializationError(org.junit.runner.manipulation.Filter) 
    | java.lang.Exception: No tests found matching grails test target
    pattern filter from org.junit.runner.Request$1@12c27788
      at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:138) 
    | Completed 1 unit test, 1 failed in 0m 0s 
    | Error Fatal error running tests: Not-null property references a transient value - transient instance must be saved before current operation : newmyproject245.Order.product -> newmyproject245.Product; nested exception is org.hibernate.TransientPropertyValueException: Not-null property references a transient value - transient instance must be saved before current operation : newmyproject245.Order.product -> newmyproject245.Product (Use --stacktrace to see the full trace)</p>
  </blockquote>
  
  <p>someone help. Again, Thanks!</p>