By this point you should be able to set up Fest, open your application and access the various components on your user interface. If done right you should have even set up an example that opens a native using the user interface as if a user has performed the actions.
Now, lets test this program, shall we.
How am I looking?
If you are testing search and highlighting functionalities like I have been you will proberly want to compare the look of the window at given times after given functionality has been called. These tests are a great way of testing what the user output will be. This is relatively easy to achieve.
First we need to get access to our BasicRobot (we are calling this object robotf). The BasicRobot has access to a method that will create an image based on screen coordinate passed to it.
Using this method we can take a picture of the screen when we have triggered the functionality we wish to test.
Next we compare this to a baseline created in the same way that we know to be correct. First compare the the file size of the created image and the baseline image. If they are different then the files are different.
If you are incredibly unlucking or believe that the image may have the same size but still have difference (this is incredibly rare) you need to run through the image pixel at a time comparing the RGB values of each pixel.
Spot the difference
So the two images look incredibly similar. How do you know where the difference is?
Well first of all get the Graphics2D object for the image created by your test. Now for every pixel in the created image that is not the same as the corresponding pixel in the baseline image set the pixel to cyan. If the pixel is already cyan set it to a magenta pixel. Or your could draw the inverse color of the pixel. Whatever technique you would prefer to use to show the difference, change the pixels to a different color to make them stand out compared to the baseline. This can be done as follows.
BufferedImage baseline; BufferedImage testImage; /*Create test image and load baseline image here*/ for (int x=0;x
Going on beyond this is now up to you. If you wish to try Fest yourself it can be found at http://fest.easytesting.org/
This post is part of our “Testing Articles Index” in these articles we provide a guide to Testing.
Latest posts by Kieran France (see all)
- How to use Cipher streams in Java - January 10, 2018
- Improved Shape Rendering with Soft Clipping - August 24, 2017
- 4 Hidden Features in Java 9 - May 30, 2017
- Why HTTP/2 Client in Java 9 is important - May 23, 2017
- PDF Portfolio support added to JPedal, so what are they? - April 4, 2017