testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.99k stars 1.02k forks source link

TestNg not generating reports in case of timeout #1215

Open mantryashutosh opened 8 years ago

mantryashutosh commented 8 years ago

Hi, We are trying to run testNg suite programmatically in java. We have defined our custom timeout check where we loop through to check if the timeout has reached. Once the timeout is reached we exit with status code 1. However, we find that no testNg report gets generated. Is there any method that we can call to make sure that the reports gets generated ? Thanks

juherr commented 8 years ago

Hi! Thanks for the report. Could you share a sample?

krmahadevan commented 8 years ago

Adding the relevant Google forum thread : https://groups.google.com/forum/#!topic/testng-users/6cPkg9Hga0Y

juherr commented 8 years ago

Example from Google thread but still unclear for me:

public class ExecIdTestNG {

    private int executeTests() {        
        int status = 0;
        final ExecutionIdRunner runner = new ExecutionIdRunner();
        runner.start();
        long start = System.currentTimeMillis();
        // 10 mins timeout
        while (System.currentTimeMillis() - start < 600000) {   
            // do nothing
        }

        if (runner.isAlive()){
            status = 1;
        }   
        return status;
    }

    private static class ExecutionIdRunner extends Thread {

        @Override
        public void run() {         
            final TestNG testNg = new TestNG(false);            
            // added few listeners          
            // added few reporters          
            final XmlSuite suite = new XmlSuite();
            suite.setParallel("classes");
            suite.setThreadCount(40);
            suite.setVerbose(10);
            suite.setAllowReturnValues(false);
            suite.setPreserveOrder("false");

            final List<XmlSuite> suites = new ArrayList<XmlSuite>();
            suites.add(suite)
            testNg.setXmlSuites(suites);
            testNg.run();
        }
    }

    public static void main(final String[] args) {
        final ExecIdTestNG tests = new ExecIdTestNG();
        int status = tests.executeTests()
        Systme.exit(status);
    }       
}