TestNG Showcase – Exceptions Testing

Similar to JUnit 4 testing, TestNG is providing functionality to check exceptions are thrown when we are expecting them to be thrown.

A simple example:

package com.dimitrisli.testng.exceptionTesting;

import org.testng.annotations.Test;

public class ExceptionsTesting {

	@Test(expectedExceptions = NullPointerException.class)
	public void method(){
		throw new NullPointerException();

	@Test(expectedExceptions = IllegalArgumentException.class)
	public void method2(){
		throw new IllegalArgumentException();

The overall code concerning the TestNG showcasing can be found in this Github repository.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s