This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 163824

Summary: Support for JUnit4 qa-functional tests
Product: platform Reporter: lujop <lujop>
Component: NB JUnitAssignee: Jaroslav Tulach <jtulach>
Status: RESOLVED WONTFIX    
Severity: blocker CC: jglick, jtulach, lujop, tomwheeler
Priority: P4 Keywords: API
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description lujop 2009-04-27 22:45:51 UTC
Although is possible to use JUnit 4 test in the platform the fact that NbModuleSuite doesn't work for Junit 4 test make
that in practice functional test can't be done.
Comment 1 lujop 2009-04-27 23:13:19 UTC
I forgot to say in my last comment that in fact I think that will be good for that class to have less dependencies to be
able to be used for other test frameworks like TestNG
Comment 2 Jesse Glick 2009-04-28 00:11:12 UTC
Unclear if this is even possible to fix: JUnit 3 allows you to return a Test from a suite() method according to
arbitrary calculations, which NbModuleSuite's existing API relies on, whereas JUnit 4 seems to rely on annotations.
Perhaps it would be possible to have a parallel API:

@RunWith(NbModuleSuite4.class)
@NbModuleSuite4.Config(clusters=".*", modules=".*", gui=false)
public class MyFuncTest {
  @Test public void first() {...}
  @Test public void second() {...}
}

Of more concern is whether any of the useful functionality in NbTestCase (used also by unit tests) would survive.
Potentially a lot of work to make this happen; may be WONTFIX since the existing JUnit 3-based idioms work, even with
JUnit 4 in the classpath.
Comment 3 Jaroslav Tulach 2009-04-28 15:21:50 UTC
I do not find the benefits of JUnit4 (except of full compatibility with JUnit3) tempting enough to work on this issue.
Comment 4 lujop 2009-05-03 10:51:45 UTC
I understand that his is not a priority one but I think that functionality like the @BeforeClass will simplify tests
because now I don't know how to reproduce easily with the existent solution. Also I think that some work needed here
will allow to use other test frameworks for functional tests.

And about implementation details:
By now the platform works well for Junit4 tests, the major problem is only the runInRuntimeContainer method that it's
coupled with TestCase. 
I think that a solution could be implement a NBModuleSuite4 with syntax like Jesse said. And that class could extend
BlockJUnit4ClassRunner or similar and override only the run() or runChild() to inject the platform start
(runInRuntimeContainer code).

Althouth I've to confess that I'm not a platform nor a Junit expert it seems to me more a refactor job making the
runInContainer not dependent of TestCase and outside of the NbTestSuite than an big design one.
But of course sometimes the evil is in the details ;)
That also will open the door to make functional tests with other frameworks like XTest, that I've seen that there is
some work for upcoming versions...

And about the functionality in NBTestCase I think that it's a minor issue at least for platform apps.
But a solution could be to make a NBAssert class to be used with static imports that delegates to static utility methods.
Comment 5 Jesse Glick 2009-05-04 17:39:55 UTC
Using a static import for NbTestCase assertion methods is trivial. I was referring to other important functionality
which is tightly bound to JUnit 3 APIs and might not be trivially ported to JUnit 4 runners: runInEQ, timeouts, log
capture on failure, @RandomlyFails, etc.
Comment 6 Jesse Glick 2010-10-07 14:45:06 UTC
Potentially a lot of work, with only modest benefit. I don't think anyone has the time to do this. In the meantime, if you want to take advantage of most of the features of nbjunit you must write JUnit 3.x-format tests.