Over a million developers have joined DZone.

Testing Exceptions on the NetBeans Platform on Maven

DZone's Guide to

Testing Exceptions on the NetBeans Platform on Maven

· Java Zone ·
Free Resource

The CMS developers love. Open Source, API-first and Enterprise-grade. Try BloomReach CMS for free.

Testing for expected exceptions does not work correctly in junit <= 4.5

Junit4 provided the functionality to test for expected exceptions. Expected exceptions can be tested with the method annotation @Test:

public void testSomeException() throws SomeException {
// some code that is expected to throw SomeException

However, in junit version < 4.5  this does not work like it should (not at all, tests will fail if expected exception gets thrown). The Maven module for the NetBeans extention for junit has a dependency on a wrapper around junit version 4.5. To be able to test for exceptions, a higher version of junit is needed. This is easily achieved by excluding the dependency on the junit 4.5 wrapper and explicitly declaring a dependency on a junit with a higher version (like 4.8.2 in our case).




BloomReach CMS: the API-first CMS of the future. Open-source & enterprise-grade. - As a Java developer, you will feel at home using Maven builds and your favorite IDE (e.g. Eclipse or IntelliJ) and continuous integration server (e.g. Jenkins). Manage your Java objects using Spring Framework, write your templates in JSP or Freemarker. Try for free.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}