1 Reply Latest reply on Nov 10, 2010 1:29 PM by toddpi314

    SeamTest - Using many small tests to integrate into a bigger test

    wolfenstein
      Hello, i´ve create three tests, one to test the users´s CRUD, second to test product´s CRUD and the last to test an Invoice CRUD.

      In my main test, i have to test report invoice process, but to do that i have to call UserCrudTest, ProductCrudText and InvoiceCrudText. ´Cause i need to use UserCrudTest to create some users to access to system, ProductCrudTest to use the users create before to create product to sell. And finale call InvoiceCrudTest to fill some invoices to print them.

      My problem is that in my PrintInvoiceTest i just try to do some thing like:

      public void testPrintInvoice(){
        UserCrudTest userCrudTest = new UserCrudTest();
        ProductCrudTest productCrudTest = new ProductCrudTest();
        InvoiceCrudTest invoiceCrudTest = new InvoiceCrudTest();

        userCrudTest.createUser( "john" );
        productCrudTest.createProduct( "grue" );
        int invoiceId = invoiceCrudText.createInvoice( "john", "grue" );

        Assert.assertTrue(  printInvoice( invoiceId );
      }

      All of those tests extend SeamTest, and that class inicializes some features using @BeforeClass, like needed tasks for FacesRequest. And if i try to reuse those tests like above, i got some null error.

      Am i doing it right?

      `||`

        • 1. Re: SeamTest - Using many small tests to integrate into a bigger test
          toddpi314
          I would suggest creating well designed super-types for your test classes.

          Unit Tests and Seam Tests work off of Annotations. The SeamTest base, or Db test extension, use the annotations to build up a bootstrap application server before/after methods/classes run.

          Annotations are 'discovered' at runtime via Java Reflection. So, using types that have @BeforeClass, @BeforeMethod, and @Test annotations is totally different than the test container creating types with those annotations; in the latter scenario, reflection can discover the annotations and work with them.

          You could do something like this:

          public abstract class ActionTest extends SeamTest {
              private static Log log = Logging.getLog(ActionTest.class);

              @BeforeMethod(alwaysRun = true)
              @Override
              public void begin(java.lang.reflect.Method method) {
                  // your code here
                  super.begin(method);
                  // your code here
              };

               public void createInvoice(String name, String lastName)
               {
                    .. impl.
               }
          }

          @Test(description = "ProductCrud Test")
          public class ProductCrudTest extends ActionTest {

               @Test
               public void doTest()
               {
                  new FacesRequest("/yourViewId.xhtml") {
                      @Override
                      protected void invokeApplication() throws Exception {
                          // your test
                         createInvoice("john", "grue");
                      }
                  }.run();
               }
          }


          @Test(description = "InvoiceCrud Test")
          public class InvoiceCrudTest extends ActionTest {

               @Test
               public void doTest()
               {
                  new FacesRequest("/yourViewId.xhtml") {
                      @Override
                      protected void invokeApplication() throws Exception {
                          // your test
                         createInvoice("john", "grue");
                      }
                  }.run();
               }
          }


          Hope that helps.