开发者

Why this exception not thrown under Junit in Eclipse?

all

I am scratching my head over a problem I ran into with junit test under Eclipse in particular: Basically, I have a junit 4 test class, the initialization method annotated with @BeforeClass tries to set up the DB connection, which essentially calls:

    try {
        return DriverManager.getConnection (DB_CONNECTION_URL,
                                            DB_USERNAME,
                                            DB_PASSWORD);
    } catch (SQLException ex) {
        throw new MyPers开发者_JS百科istenceException("Error: unable to connect to database");
    }

Now, if I ran the code in a standalone main(), the exception is thrown as expected when database is offline. However, as soon as I move it into junit @BeforeClass, the exception seems lost in blackhole - you can still trace to the exception (remember, the database is offline), but nothing prints in the console.

I am baffled by the behavior, and seems have something to do with Eclipse and Junit in particular (the same unit test run fine under NetBean) - so it is a kind shot in the dark to see anyone experience any similar problem or got any idea ...

Thanks

Oliver


I think this might be a bug in the Eclipse plugin. I've traced the code in JUnit 4 source. The class RunBefores will throw an exception as you mention. However, the exception will go into the EachTestNotifier's failure list via the addFailure. If the plugin is ignoring something, it could explain why the issue is missed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜