When we talk about custom reports, the most common question is what should be inside? What information could be useful for team or management? I saw different reports' implementations with a good level of details, but often people forget to put one important thing - execution steps.
Let's imaging some hand-written test case. It contains id / name, description, steps and some expected result. If we open any good bug report, we would see the same detailed description with steps, actual / expected results, etc. Such kind of details level has a positive impact on issue's root cause analysis, as well as on its fixing time.
When we develop tests, such frameworks as TestNG or JUnit put test name and assertion results into final report. But what's about test execution steps? When we look at report's body, who can say what was exactly tested in particular test? We can only assume real scenario. That's why I've started looking at a way of implementing such functionality. Of course someone can point that Thucydides already has such functionality, but as I've mentioned in my previous article, sometimes it's very expensive to switch to another framework only because it has a good reporting engine.
So how we can log our test execution steps? It could be done via proxy or AOP. In this article I'll talk about test execution steps logging with AspectJ.
To use AspectJ functionality, you need to include the following dependency and plugin:
Let's imaging some hand-written test case. It contains id / name, description, steps and some expected result. If we open any good bug report, we would see the same detailed description with steps, actual / expected results, etc. Such kind of details level has a positive impact on issue's root cause analysis, as well as on its fixing time.
When we develop tests, such frameworks as TestNG or JUnit put test name and assertion results into final report. But what's about test execution steps? When we look at report's body, who can say what was exactly tested in particular test? We can only assume real scenario. That's why I've started looking at a way of implementing such functionality. Of course someone can point that Thucydides already has such functionality, but as I've mentioned in my previous article, sometimes it's very expensive to switch to another framework only because it has a good reporting engine.
So how we can log our test execution steps? It could be done via proxy or AOP. In this article I'll talk about test execution steps logging with AspectJ.
To use AspectJ functionality, you need to include the following dependency and plugin:
Let's assume we're using PageObject pattern. In such case test steps would be PageObject's methods. So the main goal is to intercept PageObject's methods calls and save their names in some container to get further access, when we need to print steps into report. That can be easily done with aspects. But as you know, PageObjects may contain some useless for test results report methods (getters, helpers, etc.). So let's assume we want to filter methods to print only real test logic without any redundant calls. This can be achieved via custom annotation.
We can use this annotation for marking methods we want to publish into report.
Finally, we're ready to create a simple aspect that will intercept all the methods calls annotated with Publish annotation inside particular package:
After finishing test execution, you can easily print intercepted steps, that were saved inside ThreadLocal container. Let's see how could it look like in test results report:
You can find a source code example on GitHub.
No comments:
Post a Comment