Explicit wait statements in unit testing

  • 1 Replies
  • 1091 Views
Explicit wait statements in unit testing
« on: March 23, 2016, 09:20:05 am »
What is so harmful in explicit sleep statements in UI testing that i read everywhere that it is discouraged ?
« Last Edit: April 03, 2016, 17:53:17 pm by Sebastian »

*

Oren

  • **
  • 59
Re: Explicit wait statements in unit testing
« Reply #1 on: April 04, 2016, 18:23:47 pm »
Typically a sleep statement would pose as a delay in the application under test - one that does not exist during the test execution.

This is a bad practice since a programmatic delay is only a fake (mockup) of the actual delay in the application, and it will not be able to duplicate the complexity of the real delay.

If you were to take a network delay for example. Assume your app would take about 2-3 seconds to get some data over the network, and then proccess/render/parse it. So, under a test you would mock the data and throw in a 3 second sleep.

As simple as that sounds, this method of testing is inaccurate. You test cannot reflect how things will turn out in a real production enviroment. What if you have network problems or the data is unavailable? You are trying to test elements that are out of your control.
The 3 seconds sleep cannot replicate a network delay because most likely every data fetch over the network will be different from the previous one.

 

Sitemap 1 2 3 4 5 6 7 8