Deterministic Way of Test Automation

Test automation scripts should be simple. This doesn't mean that software product code should be complex. Actually,when everything is simple then the life will be simpler. However sometimes we need to explain something in a complex way. Most of the time, simple is difficult. There may be different reasons behind the complexity but it is clear that if we knew it clearly, we would explain it simply. Let's look at what Albert Einstein says: 

"If you can't explain it simply, you don't understand it well enough."

As the subject is how simplicity can be applied to test automation, I will focus on simple but efficient test scripts. To enable to write simple test scripts, we must clarify undefined, non-clear, dependent factors on every case/stories. This kind of approach is called as determinism in philosophy. According to the Princeton University dictionary, determinism means as: 

"determinism ((philosophy) a philosophical theory holding that all events are inevitable consequences of antecedent sufficient causes; often understood as denying the possibility of free will)"

This approach is used in software industry as every deterministic conditions are  called as state machine. As a test technique, we state transition table to create test cases. In this method every states is discrete and deterministic so that passing from one state to another state, we know pre-conditions and the result. Therefore any unexpected results can be classified as a bug.    

To define a state as deterministic, we must test if it has any un-deterministic characters. The following items should be passed: 
  1. Check if any time delay what happens
  2. Check if every case is discrete
  3. Check if every inputs to the state are determined
  4. Check if the failure of the another state effect the output
  5. Check if the assumptions are determined
  6. Check if you cover an unexpected condition happens 

If you have an un-deterministic state, you must think the out-of-the box. As a solution, Martin Fowler suggests the following solutions:
  • Quarantine: any un-deterministic test should be isolated from others and put in another test suite. By this way, other deterministic test cases will be in secure. But do not forget, there is a case waiting to be solved in quarantine.
  • Isolation: Every test case should be discrete. So as starting a case it should prepare its precondition and after the case finishes, it should draw back the test suite. A test case should not use a variable or instance which is produced by another test case.
  • Asynchronous Behaviours: If there is a time delay between actions, an easy way to add a constant sleep time. However, time may not enough for situations. There are two options, first one is to wait a replay until the response is come an then perform second actions. The second method is to ask regularly if the expected result is performed.
  • Remote Services: Prepare remote services for testing purpose but be sure that it should be deterministic.
  • Time: If you have time related test cases, before starting the test case you should wrap the time.
for detail information you can read this blog.  

Example for Deterministic Test Case

Let's create user for an e-commerce site. To create a user we need a e-mail account which is not used before. In the example, before using the e-mail address is checking from database and deleted it is exit. 

For the second test case, we are checking if the e-mail field is giving a warning when we use already registered email. To create a discrete test case, a user registered with given e-mail but this we don't delete from database so create different state and then trying to use same e-mail and then checking if the warning is given.



Popular posts from this blog

Testing WEB Sevices and Automating SOAP Services

Performance Testing on CI: Locust is running on Jenkins

Change Default Timeout and Wait Time of Capybara

Performance Testing on CI: Integration of Locust and Jenkins

Create an Alias for Interactive Console Work: Selenium and Capybara