Java Code Examples for org.testng.ITestContext

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project reportng, under directory /reportng/src/java/main/org/uncommons/reportng/.

Source file: ReportNGUtils.java

  24 
vote

/** 
 * Returns the timestamp for the time at which the suite finished executing. This is determined by finding the latest end time for each of the individual tests in the suite.
 * @param suite The suite to find the end time of. 
 * @return The end time (as a number of milliseconds since 00:00 1st January 1970 UTC).
 */
private long getEndTime(ISuite suite,IInvokedMethod method){
  for (  Map.Entry<String,ISuiteResult> entry : suite.getResults().entrySet()) {
    ITestContext testContext=entry.getValue().getTestContext();
    for (    ITestNGMethod m : testContext.getAllTestMethods()) {
      if (method == m) {
        return testContext.getEndDate().getTime();
      }
    }
    for (    ITestNGMethod m : testContext.getPassedConfigurations().getAllMethods()) {
      if (method == m) {
        return testContext.getEndDate().getTime();
      }
    }
    for (    ITestNGMethod m : testContext.getFailedConfigurations().getAllMethods()) {
      if (method == m) {
        return testContext.getEndDate().getTime();
      }
    }
  }
  throw new IllegalStateException("Could not find matching end time.");
}
 

Example 2

From project byteman, under directory /contrib/bmunit/src/org/jboss/byteman/contrib/bmunit/.

Source file: BMNGListener.java

  21 
vote

public void onFinish(ITestContext context){
  Class<?> testClass=context.getCurrentXmlTest().getXmlClasses().get(0).getSupportClass();
  try {
    bmngAfterClass(testClass);
  }
 catch (  Exception e) {
    throw new TestNGException(e);
  }
}
 

Example 3

From project Arecibo, under directory /collector/src/test/java/com/ning/arecibo/collector/.

Source file: TestModulesFactory.java

  19 
vote

@Override public Module createModule(final ITestContext context,final Class<?> testClass){
  if (!basePath.mkdir()) {
    throw new IllegalStateException("Unable to create " + basePath.toString());
  }
  final int port;
  try {
    final ServerSocket socket=new ServerSocket(0);
    port=socket.getLocalPort();
    socket.close();
  }
 catch (  IOException e) {
    throw new IllegalStateException(e);
  }
  if (System.getProperty("arecibo.collector.timelines.performForegroundWrites") == null) {
    System.setProperty("arecibo.collector.timelines.performForegroundWrites","true");
  }
  System.setProperty("arecibo.collector.timelines.chunksToAggregate","2");
  System.setProperty("arecibo.collector.timelines.spoolDir",basePath.getAbsolutePath());
  System.setProperty("arecibo.jetty.port",String.valueOf(port));
  return new AbstractModule(){
    @Override protected void configure(){
      bind(String.class).annotatedWith(Names.named(TEST_JETTY_HOST)).toInstance("127.0.0.1");
      bind(Integer.class).annotatedWith(Names.named(TEST_JETTY_PORT)).toInstance(port);
      install(new LifecycleModule());
      install(new EmbeddedJettyJerseyModule("(.)*/rest/.*",ImmutableList.<String>of("com.ning.arecibo.event.receiver","com.ning.arecibo.collector.resources","com.ning.arecibo.util.jaxrs")));
      install(new UDPEventReceiverModule());
      install(new RMIModule());
      install(new CollectorTestModule());
      install(new CollectorRESTEventReceiverModule());
    }
  }
;
}
 

Example 4

From project byteman, under directory /contrib/bmunit/src/org/jboss/byteman/contrib/bmunit/.

Source file: BMNGListener.java

  19 
vote

public void onStart(ITestContext context){
  Class<?> testClass=context.getCurrentXmlTest().getXmlClasses().get(0).getSupportClass();
  try {
    bmngBeforeClass(testClass);
  }
 catch (  Exception e) {
    throw new TestNGException(e);
  }
}
 

Example 5

From project flexmojos, under directory /flexmojos-testing/flexmojos-test-harness/src/test/java/net/flexmojos/oss/test/.

Source file: ProgressListener.java

  19 
vote

@Override public void onStart(ITestContext testContext){
  super.onStart(testContext);
  out=System.out;
  err=System.err;
  System.setOut(new PrintStream(new NullOutputStream()));
  System.setErr(new PrintStream(new NullOutputStream()));
}
 

Example 6

From project mongo-java-driver, under directory /src/test/com/mongodb/util/.

Source file: TestNGListener.java

  19 
vote

public void onFinish(ITestContext context){
  System.out.println();
  for (  ITestResult r : context.getFailedTests().getAllResults()) {
    System.out.println(r);
    System.out.println("Exception : ");
    _print(r.getThrowable());
  }
  try {
    _recordResults(context);
  }
 catch (  UnknownHostException e) {
    e.printStackTrace();
  }
}
 

Example 7

From project mongo-java-driver, under directory /src/test/com/mongodb/util/.

Source file: TestNGListener.java

  19 
vote

private void _recordResults(ITestContext context) throws UnknownHostException {
  DBObject obj=new BasicDBObject();
  for (  ITestResult r : context.getPassedTests().getAllResults()) {
    obj.put((r.getTestClass().getName() + "." + r.getName()).replace('.','_'),r.getEndMillis() - r.getStartMillis());
  }
  obj.put("total",context.getEndDate().getTime() - context.getStartDate().getTime());
  obj.put("time",System.currentTimeMillis());
  Mongo mongo=new Mongo();
  try {
    mongo.getDB("results").getCollection("testng").save(obj);
  }
 catch (  Exception e) {
    System.err.println("\nUnable to save test results to the db.");
    e.printStackTrace();
  }
 finally {
    mongo.close();
  }
}
 

Example 8

From project reportng, under directory /reportng/src/java/main/org/uncommons/reportng/.

Source file: ReportNGUtils.java

  19 
vote

/** 
 * Returns the aggregate of the elapsed times for each test result.
 * @param context The test results.
 * @return The sum of the test durations.
 */
public long getDuration(ITestContext context){
  long duration=getDuration(context.getPassedConfigurations().getAllResults());
  duration+=getDuration(context.getPassedTests().getAllResults());
  duration+=getDuration(context.getSkippedConfigurations().getAllResults());
  duration+=getDuration(context.getSkippedTests().getAllResults());
  duration+=getDuration(context.getFailedConfigurations().getAllResults());
  duration+=getDuration(context.getFailedTests().getAllResults());
  return duration;
}