For unit tests of the Android UI class, some of the previously written code was sleep 10 seconds, and then the naked eye checked. This is not used in automated tests.
Today changes the code, in fact, the visual inspection is to check the color of the pixel, so you can directly get the color of a point of view, and then compare with the expected value of the line.
This is the code that gets the color of a pixel in the view:
Public Static intGetColor (View view,intXinty) {intW =view.getwidth (); inth =view.getheight (); if(x >= 0 && x < w && y >= 0 && y <h) {Bitmap bmp=Bitmap.createbitmap (W, H, Bitmap.Config.ARGB_8888); Canvas Canvas=NewCanvas (BMP); View.draw (canvas); returnbmp.getpixel (x, y); } return0; }
To calculate the distance between four elements (RGBA) of two colors, you can use this method if you only need to have a similar color and not exactly the same:
Public Static int getcolordistance (intint color2) { return (int) MATH.SQRT ( -color.red (Color2), 2) + Math.pow (Color.green (Color1)-Color.green (Color2), 2) + Math.pow (Color.Blue (Color1)-Color.Blue (Color2), 2) + Math.pow (Color.alpha ( Color1)-Color.alpha (Color2), 2)); }
The Android unit test replaces the naked eye with a color comparison.