在没有实例化 ejb 容器的情况下,JUnit 无法在 GlassFish v3 上与 JSF 一起使用,这对吗?

发布于 2024-10-14 07:05:57 字数 1828 浏览 6 评论 0原文

我正在为我的论文开发一个网络应用程序。现在我正在那个部分,我想在该网络应用程序上运行自动化测试。问题是,我无法运行此测试。 Stacjtrace 说他无法从我想要测试的类中找到所需的类。

我已经调试并查看了 NetBeans 加载了哪些类。似乎只有我测试的类被加载。有人告诉我,我必须运行嵌入式 GlassFish。

提前致谢

Testcase: testGetInstance(org.iav.io.IOFacadeTest):        Caused an ERROR
null
java.lang.ExceptionInInitializerError
        at org.iav.io.IOFacade.<init>(IOFacade.java:32)
        at org.iav.io.IOFacade.getInstance(IOFacade.java:47)
        at org.iav.io.IOFacadeTest.testGetInstance(IOFacadeTest.java:50)
Caused by: java.lang.NullPointerException
        at org.iav.io.LicenseListFileBean.<clinit>(LicenseListFileBean.java:47)


Testcase: testGetPoolSize(org.iav.io.IOFacadeTest):        Caused an ERROR
Could not initialize class org.iav.io.LicenseListFileBean
java.lang.NoClassDefFoundError: Could not initialize class org.iav.io.LicenseListFileBean
        at org.iav.io.IOFacade.<init>(IOFacade.java:32)
        at org.iav.io.IOFacadeTest.testGetPoolSize(IOFacadeTest.java:63)

IOFacade 类:

@ApplicationScoped
public class IOFacade extends Observable {

    private static IOFacade instance;
    private UserListFileBean userListFileBean;
    private LicenseListFileBean licenseListFileBean;
    private FileAccessorBean fileAccessorBean;

    /**
     * Constructor for this class. Initializing also dependent classes.
     * Encapsulates IO-Subsystem from beeing direct accessed.
     */
    public IOFacade() {
        licenseListFileBean = LicenseListFileBean.getInstance();
        userListFileBean = UserListFileBean.getInstance();
        fileAccessorBean = FileAccessorBean.getInstance();
        /** Registering this instance at fileAccessorBean to be notified if list
         * has changed.
         */
        addObserver(fileAccessorBean);
    }

I'am developing a web-app for my thesis. Now I'm on that part, where I want to run automated tests on that web-app. The problem is, that I'm not able to run this tests. Stacjtrace says that he could not find classes which are needen from the class that I want to test.

I've debugged and looked in NetBeans which classes are loaded. And it seems that only the class, which I test was loaded. Someone told me, that I must run an embedded GlassFish.

Thanks in advance

Testcase: testGetInstance(org.iav.io.IOFacadeTest):        Caused an ERROR
null
java.lang.ExceptionInInitializerError
        at org.iav.io.IOFacade.<init>(IOFacade.java:32)
        at org.iav.io.IOFacade.getInstance(IOFacade.java:47)
        at org.iav.io.IOFacadeTest.testGetInstance(IOFacadeTest.java:50)
Caused by: java.lang.NullPointerException
        at org.iav.io.LicenseListFileBean.<clinit>(LicenseListFileBean.java:47)


Testcase: testGetPoolSize(org.iav.io.IOFacadeTest):        Caused an ERROR
Could not initialize class org.iav.io.LicenseListFileBean
java.lang.NoClassDefFoundError: Could not initialize class org.iav.io.LicenseListFileBean
        at org.iav.io.IOFacade.<init>(IOFacade.java:32)
        at org.iav.io.IOFacadeTest.testGetPoolSize(IOFacadeTest.java:63)

The class IOFacade:

@ApplicationScoped
public class IOFacade extends Observable {

    private static IOFacade instance;
    private UserListFileBean userListFileBean;
    private LicenseListFileBean licenseListFileBean;
    private FileAccessorBean fileAccessorBean;

    /**
     * Constructor for this class. Initializing also dependent classes.
     * Encapsulates IO-Subsystem from beeing direct accessed.
     */
    public IOFacade() {
        licenseListFileBean = LicenseListFileBean.getInstance();
        userListFileBean = UserListFileBean.getInstance();
        fileAccessorBean = FileAccessorBean.getInstance();
        /** Registering this instance at fileAccessorBean to be notified if list
         * has changed.
         */
        addObserver(fileAccessorBean);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺孤伤于心 2024-10-21 07:05:57

是的,单元测试仅涉及您正在测试的类。您必须模拟单元测试的容器类。

如果您需要的是集成或系统测试,测试您的类如何与其环境交互,那么您将需要在嵌入式环境中运行您的应用程序。查看 Arquillian,它提供了一种简单易用的方法来管理您的嵌入式测试环境。适用于 Glassfish 3.0.1、JBoss 和其他一些容器。

Yes, a unit test involves only the class you are testing. You have to mock out the container classes for your unit test.

If what you are after is an integration or systems test, which tests how your class interacts with it's environment, then you will need to run your application in an embedded environment. Check out Arquillian, it provides a simple easy to use way to manage your embedded test environment. Works with Glassfish 3.0.1, JBoss, and some other containers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文