Skip to main content

Testing of Automated Tests?

I've often mentioned how important automated tests are throughout my blog. However, automated tests can also give false positives... This is where paired programming and testing of the automated tests come in to play. The example I am going to use employs the Page Object model with BDD, more of which can be read about here and here, until I get round to creating a new blog post on it...


Scenario Outline: Search for generic term
Given I am on the homepage
And I have entered <searchterm> into the search box
When I click search
Then search results for <searchterm> are displayed

Let me explain anyway, if we have an assertion in the step definition for the Then step (written in C# using NUnit) that does the following:






[Then(@"search results for (.*) are displayed")]
        public void SearchResultsForAreDisplayed(string searchTerm)
        {
            Assert.IsTrue(_searchPage.SearchTitleTextDisplayed(searchTerm));
        }

(_searchPage.SearchTitleTextDisplayed(searchTerm) is a method that lives in the page object for Search Page, that returns true if the SearchTitleText is displayed, the same can be assumed for the methods mentioned below)

It's asserting that the search results header is displayed on the page, signifying one would suspect that the search was successful.

However, upon closer inspection that search results header is also displayed when there are no search results:



So now, we have a test that looking at the Step Definition is asserting that the search results header is displayed, which it is, and passing the test as a success for having search results displayed. The problem, which I'm sure you've already guessed, is that the search results header is also displayed when there are no search results, so this means the test will pass regardless if search results are displayed or not.

A much better approach, would be to assert that products are displayed and that there are refinements as well as the search results header. So we now have:

        [Then(@"search results for (.*) are displayed")]
        public void SearchResultsForAreDisplayed(string searchTerm)
        {
            Assert.IsTrue(_searchPage.SearchTitleTextDisplayed(searchTerm)), "Search Title is not displayed";
            Assert.IsTrue(_searchPage.SearchResultsDisplayed()), "No Search Results are displayed";
            Assert.IsTrue(_searchPage.RefinementsDisplayed()), "There are no refinements displayed";
        }

These new assertions, mean that if one of them fail, the test fails, and you get information on the assertion that failed.

 You could argue the case for having one assertion, that correlated all of the above into one simple assertion at the step level:

        [Then(@"search results for (.*) are displayed")]
        public void SearchResultsForAreDisplayed(string searchTerm)
        {
            Assert.IsTrue(_searchPage.SearchPageResultsDisplayed(searchTerm)), "Search Results Page is not displayed correctly";
        }


However, out of the 2, I prefer the original method, with 3 different assertions, purely for 2 reasons:

  • The step is easy to read and understand what it is doing.
  • If one of the assertions fail, then the message displayed is more informative for debugging purposes than the second method (you could return the message that fails to the assertion, but it's still not as clear in my opinion)
There is the positive of the step definition getting larger as you want to assert more and more things on the step (with the earlier method), I would however say that ideally there shouldn't be more than 1 assertions per a step (although i am sure there are exceptions to the rule)....

So, based on the above (1 assertion per step and to keep sizes of steps to a minimum), we can improve this even further, you could have multiple steps, with one assertion in each, this is much cleaner, and probably my favoured method. 

        [Then(@"search results for (.*) are displayed")]
        public void SearchResultsForAreDisplayed(string searchTerm)
        {
            Assert.IsTrue(_searchPage.SearchResultsDisplayed()), "No Search Results are displayed";

        }
        [Then(@"search title text of (.*) are displayed")]
        public void SearchTitleTextOfDisplayed(string searchTerm)
        {
            Assert.IsTrue(_searchPage.SearchTitleTextDisplayed(searchTerm)), "Search Title is not displayed";

        }      
        [Then(@"search refinements are displayed")]
        public void SearchRefinementsAreDisplayed()
        {
            Assert.IsTrue(_searchPage.RefinementsDisplayed()), "There are no refinements displayed";

        }


This gives you the benefit of individual error messages should one fail, and at the same time they will fail the test if one of them fails and they keep the step definition down to a minimal size. This results in a new Scenario Outline of the following:

Scenario Outline: Search for generic term
Given I am on the homepage
And I have entered <searchterm> into the search box
When I click search
Then search results for <searchterm> are displayed
And search title text of <searchterm> is displayed
And search refinements are displayed

It's a lot more informative for the tester who is running the test to see exactly what it is doing, even without looking at the code, they can see instantly what checks are being performed.

We could add more checks, but for the sake of this exercise, it's important to grasp what the automated test is checking for, before it is being written. It's also important to structure the test with what you want to test in mind

This example highlights the importance of the tester either writing the steps themselves or pairing with a developer as they create the tests, as a developer may feel that the first example is enough, but obviously, as QA we know we have to test the automated tests themselves, to ensure that the tests don't give false positives. 

If I'm honest, i prefer the pairing with the developer approach, as then knowledge is shared, and the QA and Dev learn a little bit more about the others skill set and it helps build team relationships.


Comments

  1. can you share the code snippet of this example? I am new to Gherkin and specflow very keen to learn this, but having difficulties with the actual implementation using specflow, I have tried to search on the internet but none of them are not complete.

    Thanks,
    Amar

    ReplyDelete
    Replies
    1. Sure thing. It's here: https://github.com/gwaterhouse85/AsosSpecifications

      Delete
  2. I am also strongly motivated to learn the language but getting some difficulties in coding. I'm searching for those problems over Internet but coulds't find the solution. Maybe you can help me out.

    ReplyDelete
  3. REALLY VERY EXCELLENT INFORMATION. I AM VERY GLAD TO SEE YOUR BLOG FOR THIS INFORMATION. THANKS FOR SHARING. KEEP UPDATING.

    NO.1 AQM Services | Application Quality Managment Services | Austere Technologies

    ReplyDelete
  4. wow...nice blog, very helpful information. Thanks for sharing.

    NO.1 API DEVELOPMENT SERVICES | MASSIL TECHNOLOGIES

    ReplyDelete

Post a Comment

Popular posts from this blog

Testers: Be more like a Super-Villain!

Who doesn't love a Super Hero? Talk to my son, and he'll tell you how much he loves them, talk to many adults and they'll say the same! Deep down, we all love to be the Super Hero, we all want to save the day! However, I want to talk about the flip side of Super Heroes, the Super Villains... I often play Imaginext with my son, and I (unfortunately?) am nearly always the Super Villain! Be it Lex Luthor, Joker, Two Face, Mr Freeze or The Riddler! These are all great characters and great Super Villains, but why would I want to write about Super Villains? A while ago where I worked, we had a few Super Heroes, people who would be able to come in and "fix" things that had broken and help deliver projects on time. We then shifted, we decided to do away with the Super Hero culture and try and prevent from being in that position in the first place, whilst we didn't go as far as wanting to hire Super Villains, it's definitely a story that has stuck with me and t...

QA is Awesome!

No real point to this post other than I have had the song stuck in my head and figured I could change it slightly and quite easily make QA is Awesome! Oh and I haven't even seen the movie all the way through! But for some reason that song is incredibly catchy! Not much point to this post in fact, just thought I'd put it out there :)

Measuring QA Key Skills and Competencies

I have been thinking about how I can help encourage self improvement within my team, as I understand it, everyone wants to improve, it's just that often there are a number of things that hold people back. I believe one of these things that hold people back are around identifying skills that they are perhaps weak in or that they could/should improve on. So I thought about how I can help tackle that problem. One solution that I want to try with people is to identify the key skills for a QA, what key skills should every QA have, or at least what key skills make up a good QA? If I can identify these then I can start helping people identify if they are lacking in an area. Sure there is a competency matrix that we have, but it has things like "An excellent understanding of XXX", it's often very difficult to quantify what an excellent understanding actually is. So I sat down and came up with the following key skills: OOP Test Documentation Manual Testing Automated...