0 Replies Latest reply on May 8, 2009 7:14 AM by Cesar Perez

    Help unit testing Spring + Seam

    Cesar Perez Newbie

      Hi,


      I am new to Seam and I am working in a web application using Seam, JPA and Spring. I have followed the Tutorial to integrate Spring and Seam in the Seam in Action Book - Chapter 15.


      I am able to start Seam and the Spring context but I actually have no idea how to create a simple unit test with either JUnit or TestNG. There are no examples available as far as I know in the book.


      I used to do all my testing with the Spring JUnit 4 runner:


      public class SomeTest{
          @Autowire
          MyService service;
      
          @Transactional
          public void testSomething(){
              service.myMethod();
          }
      }



      now I am trying:


      public class IntTest extends SeamTest
      {
          @Autowired
          public PersistenceService<User, String> service;
          
          @Test
          public void injectionTest() throws Exception{
              service.findById("cesar");
          }
      }



      but I always get a NullPointerException because the service is not injected, I have also tried inserting an EntityManager with the @PersistenceContext annotation in the Test class but it has the same result. I have also tried the @In annotation without success. The service is a seam component as I need it in a conversation scope.


      My Spring configuration is fine as it is exactly a copy/paste from the book and I have no problems starting the context, I just have no idea how to test this.


      Any help would be appreciated.


      Thanks