Hey everybody Caleb Stoltze here with Deb's Loeb's dot com and I'm here with a very quick video on UI
testing best practices.
These are just some things that we're going to keep in our mind as we are going throughout this section
of content and these are just best practices to keep in mind.
And a lot of them are sort of no brainers just basic principles for writing good code.
But if you have any experience with unit testing a lot of these best practices are the same.
So let's dive right in.
Number one do not rely only on UI testing automation.
OK you should still be running your app in a simulator of some kind.
Or on localhost if you're doing web development you should still be interacting with it from time to
time to ensure that everything works because you're testing like unit testing it's not perfect.
It's great.
It's helpful.
It works most of the time but it's not perfect.
So that is number one do not rely only on UI testing automation.
Number two never pause threads or use timers in your test unless there are specific test requirements
that you're given to do so.
There is a very special way in in unit testing and UI testing to essentially pause your test to wait
before continuing.
And they're called expectations that's what we're going to talk about later in this section but never
use thread or never pause threads or use timers unless you're explicitly told to do so.
Number three name your tests wisely.
OK this just makes sense.
Like a function for instance you're going to name it wisely.
A self-descriptive idea about the exact functionality being tested.
Your test names should have names like that you need to tell exactly what you're testing.
What I like to do of course you have to start your test with the word test and then I like to describe
right after that what I'm testing so I might say test log in button and then I like to put an underscore
and say the condition or what is happening so when tapped then I put another underscore and then say
the expected result.
So test log and Button underscore when tapped underscore should animate and then I would test my animations
with my testing which is very cool.
So number three is name your test wisely.
Number four make tests simpler instead of adding comments.
If you're needing to add a bunch of comments to explain what your test is testing your test is too complicated.
Make it simpler.
Maybe instead of writing a huge block of code explaining what it all does maybe put that into a function
and just call that function from your test.
Your test should be very simple and easy to read.
Ok number four make your test simpler instead of adding comments.
Number five.
All tests pass.
OK that is a policy that you should strictly adhere to if you are utilizing tests because if you allow
test to fail what's the what's the point of using them.
All tests should pass and be green before being admitted into your master repository.
So number five.
All tests pass.
Number 6.
Every test should be independent meaning one test should not rely on another test in order to pass.
Each test should be an individual cut piece that is allowed to run on its own get its own result and
not rely on any other tests.
Number six is.
All tests should be independent.
Number 7 use the console and make sure to set up some type of reporting in case of test failure.
Right now of course there are ways to do this very easily with the UI testing framework in iOS and we're
going to be looking at that in just a moment.
But make sure that you can report some way to basically tell you what's going on.
If your test fails instead of just saying it failed have it tell you why it failed and then this is
not necessarily a best practice.
But I just thought it was a neat idea.
I read about it on line and I learned that this is something that you can do.
You can basically set it up so that when your test fails the you can actually see like a screenshot
on the screen of what happened.
OK so you can actually take screenshots in your test for failure investigation so if you're like looking
into why it failed you can have a screenshot to refer to for exactly when the test fails you can see
if maybe something is off centered or maybe if something is not animated properly you can tell with
the screen shot.
Very cool stuff.
So these are some basic best practices for UI testing and now we're actually going to dive into an example
of a very very basic UI test in swift Acia there.