What I will do in the rest of this chapter is to go through all of these failing tests and fix them. Then we run them in order to see everything green. So, let's see some passed tests in this screen.
Before I do anything, I will click the Pin button.
I have a set of results here — I ran a set of tests and I got some results — and I want to compare these results with what I will have after I fixed all of the tests.
When you Pin a certain test run, that test run remains pinned and doesn't go anywhere unless you manually close it. This way you can have both a set of tests that were run with their results that you can store in this view and keep them here for a while, but at the same time you will be able to run some other tests.
So, for now I have pinned this, and I would like to start looking at the failed tests and I will start with the
I will just make this lower part of the screen a bit smaller and I would just browse through the test that is currently open to see where my test failures are.
I can easily see from the icon that this test method has failed and from this underline below beneath the
assertEquals method that this was the place where a failure occurred.
Here I will just need to adjust the assertion so that it passes.
So, the expected value for the page title was incorrect so I will just need to change ”Example title” to “Example Domain” in this test and also in the one right below.
These 2 tests had the same root cause — the expected value for them was incorrect.
Now I will run the test class because I fixed these 2 tests and I want to see that the test class passes.
I will go back to the editor. I will close the project screen for now and I will again run only the test class, not the entire package, but by clicking the icon from inside the editor.
So, on a test class level, I will just run the test.
It will again open the browser, perform its steps, and then I will show you what happened behind the scenes, namely what happened in the Run view.
The results I stored are still here, so when I pinned this screen, the results remain in this tab.
The tab is called “taudemo” because this is where I ran the entire package.
In a new tab in the Run screen, I got the results for the passed method that I ran separately. I fixed this test method and I ran the tests again independent to the initial results.
These results are stored in the first tab, and this second tab is the latest run where you can see that because I have amended the tests, they are now passing. This is beautiful.
Let's take a look at the next failure.
We have a failure in the
WithAssertionsTest class and the failure is at this line.
I would just change the expected to let's say “2”.
Because I have only 1 failing test method, I can just run this test method, not the entire class. Again, remember that the results are still pinned from the run of the package.
Now I will just run this method, and this will be really quick. The run of this method was done again in the second window where the run of the SeleniumTest was made.
The SeleniumTest run results were not pinned, I did not click the pin button here.
Therefore, in this second screen that opened in this Run screen, the results of running this last test were stored, the screen was just reused. So, this new tab was reused. IntelliJ didn’t open a new one.
Now let's go to the last test that failed because I want to fix this one too.
And again, I can take a look at the failed assertion and I can see that in this case the failure was because I didn't have the same letter case as the page title on the site.
I can again run just this test method.
It will run again in the second tab, so this is going to be reused again.
And after this is done, we have had fixed all of the tests that we have in this “taudemo” package.
So, we have the results of the initial run in this pinned tab — let's now rerun only the failed tests.
Let's click the Rerun Failed Tests and see what happens.
At this point a new tab will be open and the results will be stored there because I had closed the second tab before I started running the tests. The test results of the newly updated methods will be stored in the newly open tab.
As you can see, the result of this latest test run is passed all over, so all of the test methods were fixed. Everything is working fine.
I will close this Rerun Failed Test pin in for now or tab for now because I want to run all of the tests. So not just failed ones but also the ones that passed.
I will just run the entire package by clicking the Run button next to the package.
Let's wait for the results.
All of the results that I initially stored here were replaced by the new results.
That's because I reran the exact same command on the exact same set of tests in the exact same window. So, in this case, the results weren't stored anymore.
And as you noticed earlier, when I reran only the failed tests, that opened a new tab with the set of results only for those separate tests that I ran, which were only the failed tests.
So, this is how you run your tests.
Again, if we recap shortly, you can run a package, a class or a method.
You can give the run commands either from directly within the editor or from the project screen by right clicking on what you want to run and selecting Run.
You can also edit configurations from the Edit Configuration screen.
Keep in mind that when you want to change a configuration so that a new configuration applies to all of the tests run from that moment on, you need to delete all of the entries from the JUnit entry, if you're working with JUnit. Or TestNG if you're working with TestNG. So just delete them and then go to Templates, JUnit for example, and change the value of this configuration that you're interested in.
For now, I will just delete this one because in the next chapter we will discuss debugging and I will show you how to debug the test when you have some issue and you can't easily figure out what is going on.