06
Apr

Default execution on configuration failures in testng

If a TestScript if configuration methods (@BeforeSuite, @AfterSuite) fails the output captures the results as follow:

===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================

===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================

In order to customize Configuration failures, we can implement IConfigurationListerner / IConfigurationListener2 interface as follow:

import java.util.Set;

import org.testng.IClass;
import org.testng.IConfigurationListener2;
import org.testng.ITestContext;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;

public class MyIConfigurationListenerImpl implements IConfigurationListener2, ITestResult {

@Override
public void onConfigurationSuccess(ITestResult itr) {
// TODO Auto-generated method stub

}

@Override
public void onConfigurationFailure(ITestResult itr) {

itr.setStatus(ITestResult.SKIP);
System.out.println(“Success established”);

}

@Override
public void onConfigurationSkip(ITestResult itr) {
// TODO Auto-generated method stub

}

@Override
public void beforeConfiguration(ITestResult tr) {
// TODO Auto-generated method stub

}

@Override
public Object getAttribute(String name) {
// TODO Auto-generated method stub
return null;
}

@Override
public void setAttribute(String name, Object value) {
// TODO Auto-generated method stub

}

@Override
public Set getAttributeNames() {
// TODO Auto-generated method stub
return null;
}

@Override
public Object removeAttribute(String name) {
// TODO Auto-generated method stub
return null;
}

@Override
public int compareTo(ITestResult o) {
// TODO Auto-generated method stub
return 0;
}

@Override
public int getStatus() {
// TODO Auto-generated method stub
return 0;
}

@Override
public void setStatus(int status) {
// TODO Auto-generated method stub

}

@Override
public ITestNGMethod getMethod() {
// TODO Auto-generated method stub
return null;
}

@Override
public Object[] getParameters() {
// TODO Auto-generated method stub
return null;
}

@Override
public void setParameters(Object[] parameters) {
// TODO Auto-generated method stub

}

@Override
public IClass getTestClass() {
// TODO Auto-generated method stub
return null;
}

@Override
public Throwable getThrowable() {
// TODO Auto-generated method stub
return null;
}

@Override
public void setThrowable(Throwable throwable) {
// TODO Auto-generated method stub

}

@Override
public long getStartMillis() {
// TODO Auto-generated method stub
return 0;
}

@Override
public long getEndMillis() {
// TODO Auto-generated method stub
return 0;
}

@Override
public void setEndMillis(long millis) {
// TODO Auto-generated method stub

}

@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}

@Override
public boolean isSuccess() {
// TODO Auto-generated method stub
return false;
}

@Override
public String getHost() {
// TODO Auto-generated method stub
return null;
}

@Override
public Object getInstance() {
// TODO Auto-generated method stub
return null;
}

@Override
public String getTestName() {
// TODO Auto-generated method stub
return null;
}

@Override
public String getInstanceName() {
// TODO Auto-generated method stub
return null;
}

@Override
public ITestContext getTestContext() {
// TODO Auto-generated method stub
return null;
}

}

Step 3: Customize execution via testng.xml :
——- ———————————–







OUTPUT:
——-
[RemoteTestNG] detected TestNG version 6.14.3
Sheetal
Success established

===============================================
Suite
Total tests run: 1, Failures: 0, Skips: 0
Configuration Failures: 0, Skips: 1
===============================================