TestNG Showcase – Unit Test Dependencies

A nice feature of TestNG that JUnit 4 is missing is the fact that it’s possible to specify unit tests that rely on other unit tests to complete first.

An example:

package com.dimitrisli.testng.dependents;

import org.testng.annotations.Test;

public class DependentMethodTesting {

	@Test(dependsOnMethods={"method1"})
	public void method2(){
		System.out.println("hi I am method2 and I depend on method1");
	}
	
	@Test
	public void method1(){
		System.out.println("hi I am method1");
	}
}

that produces the output:

hi I am method1
hi I am method2 and I depend on method1

The code can be found in this Github repository.

Advertisements

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