@Override public void succeeded(Description description) { System.out.println(getFullMethodName(description) + " success" + getDuration()); MemoryAppender.initialize(); }
/** * Use this constructor to set up a particular log4j configuration using a properties file * available on the classpath, or null if you do not want to load any log4j configuration * properties. * @param log4jPropertiesResourceName */ public MethodExecutionTrace(String log4jPropertiesResourceName) { healthCheck(); MemoryAppender.initialize(); if (log4jPropertiesResourceName != null) { // Initialize log4j using a properties file available on the class path Properties log4j = new Properties(); try ( InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(log4jPropertiesResourceName) ) { if (in == null) { throw new RuntimeException(String.format("Could not load resource %s", log4jPropertiesResourceName)); } log4j.load(in); PropertyConfigurator.configure(log4j); } catch (IOException e) { throw new RuntimeException(String.format("Could not load resource %s", log4jPropertiesResourceName), e); } } }
/** * Creates a rule chain containing the following rules:<ol> * <li> a timeout rule * <li> a rule to print console messages at the start and end of each test method and print trace level * log messages on test failure. * </ol> * @param timeout The maximum allowed time duration of the test * @param timeUnit The unit for the timeout * @return */ public static RuleChain createRuleChain(long timeout, TimeUnit timeUnit) { TestRule timeoutRule = timeoutRule(timeout, timeUnit); TestRule trace = new MethodExecutionTrace(); return RuleChain.outerRule(trace).around(timeoutRule); }
/** * Creates a rule (chain) out of a gateway or other rule, adding extra rules as follows:<ol> * <li> a timeout rule * <li> a rule to print console messages at the start and end of each test method and print trace level * log messages on test failure. * </ol> * @param rule Rule to startup and stop gateway * @param timeout The maximum allowed time duration of each test (including the gateway rule) * @param timeUnit The unit for the timeout * @return A TestRule which should be the only public @Rule in our robot tests */ public static RuleChain createRuleChain(TestRule gateway, long timeout, TimeUnit timeUnit) { TestRule trace = new MethodExecutionTrace(); TestRule timeoutRule = new DisableOnDebug(Timeout.builder().withTimeout(timeout, timeUnit) .withLookingForStuckThread(true).build()); return RuleChain.outerRule(trace).around(timeoutRule).around(gateway); }
@Override public void failed(Throwable e, Description description) { if (e instanceof AssumptionViolatedException) { System.out.println(format("%s skipped programmatically with reason: %s", getFullMethodName(description) , e.getMessage())); } else { System.out.println(getFullMethodName(description) + " FAILED with exception " + e + getDuration()); e.printStackTrace(System.out); System.out.println("=================== BEGIN STORED LOG MESSAGES ==========================="); MemoryAppender.printAllMessages(); System.out.println("=================== END STORED LOG MESSAGES ==========================="); } MemoryAppender.initialize(); }
/** * Creates a rule (chain) out of a k3po rule and gateway rule, adding extra rules as follows:<ol> * <li> a timeout rule * <li> a rule to print console messages at the start and end of each test method and print trace level * log messages on test failure. * </ol> * @param gateway Rule to start up and shut down the gateway (or acceptor or etc) * @param robot Rule to startup and stop k3po * @param timeout The maximum allowed time duration of each test * @param timeUnit The unit for the timeout * @return A TestRule which should be the only public @Rule in our robot tests */ public static RuleChain createRuleChain(TestRule gateway, K3poRule robot, long timeout, TimeUnit timeUnit) { TestRule trace = new MethodExecutionTrace(); TestRule timeoutRule = new DisableOnDebug(Timeout.builder().withTimeout(timeout, timeUnit) .withLookingForStuckThread(true).build()); return RuleChain.outerRule(trace).around(gateway).around(robot).around(timeoutRule); }