question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RunListener implementation questions

See original GitHub issue

I am creating a custom RunListener to update a test run on TestRail with the results from an android automation run. I have two questions:

  1. How important is to be able to declare the RunListener as thread safe?

I see if it’s not marked with @RunListener.ThreadSafe the listener will be wrapped in the SynchronizedRunListener. AFAIK, AndroidJUnitRunner will run one test at the time, so I think it doesn’t matter.

  1. Which is the best way to know if a test passed? The RunListener API doesn’t have a testPassed() (why?) so what I did is the following:
  • Create a set of Descriptions on testRunStarted()
  • If testFailure() or testAssumptionFailure() are called, add the Description instance to the set
  • When testFinished() is called, if the Description instance is not in the set, I mark the test as passed

Thanks for your time!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
marcphilippcommented, Jun 1, 2016

You know that a test passed when testFinished() is called without a prior call to testFailure() with the same Description.

0reactions
sebastianvintilacommented, Oct 14, 2019

@Macarse regarding the issue of missing testSuccess method here is the solution i have implemented

private static final Description FAILED = Description.createTestDescription(“failed”, “failed”);

public void testFinished(Description description) throws Exception { System.out.println("Finished test: " + description.getMethodName()); if (description.getChildren().contains(FAILED)) { // action for test failed } else { // action for test success } }

public void testFailure(Failure failure) throws Exception {
    System.out.println("Failed test: " + failure.getDescription().getMethodName());

// mark the test as being failed failure.getDescription().addChild(FAILED); }

Read more comments on GitHub >

github_iconTop Results From Across the Web

testSuccess method implementation for RunListener interface
My issue is that the interface has no testSuccess method. (for example the ITestListener from TEstNG framework has a onTestSuccess method) ...
Read more >
JUnit Listeners with All Details and Examples!
In this post, we will learn how to use JUnit Listeners. We will use JUnit 4 Rules to create a listeners to listen...
Read more >
JUnit Test Listener - JUnit RunListener Example
JUnit RunListener Example. 1.1. JUnit test classes. We are writing two test classes below for example only. We will monitor the logs printed...
Read more >
How to implement RunListener a JUnit Listener example
In this example we will show you how you can add a JUnit Listener to your test cases. This JUnit Listener can listen...
Read more >
Using RunListener in Android tests - Test Automation Chronicles
This step is the same for Android instrumented tests as well. package com.example.myapp;.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found