Software Technology - Development and Test Engineering, software testing

Maven + Surefire + Testng

If you are planning to write tests using Maven, Surfire and Testng then you may proceed  to the next lines.

1. Add dependency to your pom.xml

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>

2. Write your test

@Test
public void myTest(){
}

3. Run Test
how to run a single test from command-line ?

mvn clean -Dtest=<your test> test -Dvar1=<value>

  • clean is to make sure your tests are recompiled
  • <your test> should be the complete path to the class e.g. package.com.mypackage.TestClassName#testMethod
  • -Dvar1 system variables that/those you might want to pass to your tests e.g. -VtestUrl=http://google.com

how to debug ?

mvn -Dmaven.surefire.debug test

debugging a single tests

mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE" test

How to run a testng from Eclipse IDE with arguments to the tests ?

  • Goto IDE and testng run configuration
  • Write in VM arguments
    •  -D<variable_name>=<variable value>
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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s