How to capture project Junit test results in a database

We have many independent modules (say, X), and all X-modules have either

  • Junit Test Cases
  • Testng

Tests are executed whenever a developer builds a module using Jenkins. I am creating a user interface panel to show the test result for each module. In this dashboard, I will show many other things. So the result of the test cases will be just a column.

<Strong> Problem Strong>: I need a tool / plugin with which I can save junit results to the database as soon as it is created through jenkins. Is it possible, or do I need to write my own java program?

+4
source share
2 answers

You can achieve this by doing org.testng.IReporter.

The IReporter interface has only one method:

public void generateReport(List<ISuite> suites, String outputDirectory)

This method will be called by TestNG when all packages are running. Another alternative is to use a ITestListenerlistener interface or extension TestListenerAdapter.

public class MyTestListener extends TestListenerAdapter {

  @Override
  public void onTestFailure(ITestResult tr) {
    //do the needful
  }

  @Override
  public void onTestSkipped(ITestResult tr) {
    //do the needful
  }

  @Override
  public void onTestSuccess(ITestResult tr) {
    //do the needful
  }

See the TestNG documentation for more details .

+1
source

As far as I know, there is no plugin or the like.

You must implement it yourself. In the case of JUnit, you can implement TestWatcher :

@Rule
public TestWatcher watchman = new TestWatcher() {

    @Override
    protected void failed(Throwable e, Description description) {
        // Store result in DB
    }

    @Override
    protected void succeeded(Description description) {
        // Store result in DB
    }
};

https://garygregory.wordpress.com/2015/09/14/the-art-of-test-driven-development-logging-junit-test-results/

Do not want to use @Rule

, RunListener.

testStarted(Description description) testFinished(Description description) - .

maven surefire, 2.7 .

+2

All Articles