EJB3 测试

来源:互联网 发布:苹果移动数据怎么快捷 编辑:程序博客网 时间:2024/05/01 18:46
JPA可以脱离容器运行,测试比较简单。
但是,如果使用EJB3注释来注入代码就需要一个小的容器来测试了

jboss提供了一个嵌入式的容器。
http://docs.jboss.org/ejb3/embedded/embedded.html

 public static Test suite() throws Exception
   {
      TestSuite suite = new TestSuite();
      suite.addTestSuite(EmbeddedEjb3TestCase.class);


      // setup test so that embedded JBoss is started/stopped once for all tests here.
      TestSetup wrapper = new TestSetup(suite)
      {
         protected void setUp()
         {
            startupEmbeddedJboss();
         }

         protected void tearDown()
         {
            shutdownEmbeddedJboss();
         }
      };

      return wrapper;
   }

   public static void startupEmbeddedJboss()
   {
         EJB3StandaloneBootstrap.boot(null);
         EJB3StandaloneBootstrap.scanClasspath();
   }

   public static void shutdownEmbeddedJboss()
   {
      EJB3StandaloneBootstrap.shutdown();
   }

还有一个测试工具也提供了同样的能力
http://ejb3unit.sourceforge.net/
原创粉丝点击