How to log junit test run results to a database

Refresh

December 2018

Views

5.3k time

7

We use junit for integration tests. The tests are being run in Eclipse and Jenkins.

Now i would like to log all junit test run results to a database for easy reporting (i want to log test class / method name, environment, duration and success). I had thought about parsing the junit result xmls but to log it directly to a database sounds good to me, too. It sounds intrusive but also pretty elegant.

Normally we just annotate a test method with the @Test annotation and voila, we have our junit test method.

That means we have no additional framework around junit and i want to keep it that way. I fear that means that if i want to implement that kind of logging i will probably have to hack into junit.

Has anybody done so and can give advice if that works nicely? Maybe you have an idea on how/where to place the hook in junit. Or are there easier approaches to my problem?

Thanks!

edit: To clarify, we already have junit test results of single test runs. You can get them out of eclipse (export junit result) or out of jenkins. Running our junit test suites in Jenkins also allows us to track test failure rates of test suites over time. It shows you a nice chart that tracks how many tests of passed over time. In each jenkins build you can see which tests passed, also in comparison to the last run. We need a bit more. We want to be able to analyse the performance (duration) of certain testcases over time, over multiple runs, maybe also how they behave differently in different environments. Extract trends. Do some data mining.

1 answers

2

Я не уверен, если это полезно для вас, но вы можете сделать различные виды переадресаций на выходе JUnit тестов и даже указать формат для протоколов испытаний, которые вы могли бы в свою очередь, хранить в базе данных, чтобы иметь возможность доступа и с течением времени означает сохранение, для дальнейшего анализа или даже статистических целей.

Руководство с объяснением того, как это может быть достигнуто, предлагая отчеты HTML, можно найти здесь: http://www.skill-guru.com/blog/2010/03/26/generating-junit-test-results-as -html-отчет /

Надеюсь, это поможет.