Better QA: Learning from unit testing standards
“Unit Testing” is a tricky affair. I am pretty sure that testers at some point in time would have complained about the developer not doing unit testing properly and delivered a poor quality build. On the other hand, developers find it difficult to create and maintain unit test cases along with maintaining the agility of the system.
Whatsoever, there is no doubt that unit testing is a crucial part of SDLC and the first step towards testing.
Here I am going to discuss more the unit testing standards which we can leverage in our testing and automation to make it more effective and efficient.
What is unit testing?
Unit testing is a type of testing which is performed to ensure that individual units or components of the application are working as expected. The units or components, in this case, are independently tested using stubs and drivers. Unit testing is crucial as it finds out defects at an early stage and thus reducing the overall project cost and ensuring the code stability.
As a tester, It is also our responsibility to make sure that unit tests are part of our deployment pipeline. As the role of QA has evolved in the last few years, they not only perform functional and integration testing but also actively participating in unit testing. In continuous integration and delivery, the role of QA has become multidimensional and more agile. It’s important to know what unit tests are executed as a part of the release and what is the coverage. I am not going to discuss the importance of unit testing here, I believe that’s pretty clear to everyone.
This article is about how unit test cases are designed and how we can leverage that in our automation test design.
Understanding the concept of unit testing
It’s important to understand the core concept of unit testing. A unit is any entity that can be executed independently. It can be a few lines of code or an entire feature for that matter. The bottom line is it should be an independent executable piece of code. Here is the first take away.
While designing out automation framework, we should also treat our tests as a single independent unit so that they can be tested and executed independently.
Unit testing involves unit test frameworks, drivers, stubs and mocks /fake objects. It works on the basis of a white box technique where conditions, loops, and code coverage are tested.
Below are some unit testing principles which equally hold good for automation testing, let’s revisit them-
- Tests should be independent – This is the basic principle, there should not be any dependency among the test cases. This is important because one test case result should not impact subsequent cases.
In automation, we should make sure that there is no dependency such as environment setting, creating instances of shared resources and cleaning up the same.
- Tests should be deterministic – A test should either pass or fail all the time. The worst test is the one that passes some of the time. We should always have a definite reason if the test fails and when correcting that, the test should always pass.
- Tests should hold good for pass/fail cases – By this, I mean that a test should fail when it meant to fail. Put assertions carefully and run the test for a fail condition also.
- Tests should be self-validating – This means that the test should itself determine that the output is expected or not. There should not be any manual interpretation.
- Repeatable – Test should produce the same output every time it runs. This can be accomplished by making them isolated and independent.
How unit testing is performed
Unit testing requires Mocking. It works on mock objects that fill the missing part of functions to be tested. As the other components are still in development or yet to develop, we would need some piece of code to ‘act’ like those components.
Another crucial component of unit testing is APIs. APIs provide an interface for communication between two components. APIs contain business logic and the way APIs work makes it very handy to use them in unit testing.
Both mocking and API go hand in hand to perform unit testing.
How test automation leverages from unit testing
With more and more organizations going into the agile model, testing (both manual and automation) starts in the initial phase of SDLC. To expedite the process automation has a key role to play. Now we know that in agile requirements keep on changing, development is still in progress and in that situation, API and mocking can be very helpful for automation.
Use of Mock objects – Data mocking can be used to speed up the process rather than depending on the real test data. When the automation test interacts with an object’s properties rather than its functions and behaviors, mocking can be used. Mocking is mostly required when an application interacts with any external service but it can be used in other scenarios also.
A mock object can be used when the real object is:
- Slow in operation, for eg- Database access
- Hard to trigger for eg- A server crash scenario or a network error.
- Still in development.
- Not compatible or needs high-cost setup for testing environment.
There are various libraries available for Mocking. Some mocking frameworks are – Mockito, powermock, and easymock for mocking.
Use of APIs – let’s come straight to the point, APIs are faster. Also, API tests are reliable. UI tests can be flaky and slow to execute but API tests will either pass or fail. Of course, we need UI tests but its always a good idea, to begin with, API testing. APIs are developed before UI in most cases so we can always kick start with API testing.
APIs are also useful while writing integration tests and an end to end testing. We can always integrate APIs in the UI test framework to perform pre-requisite. APIs make them faster and thus reduce overall test suit execution time making it more efficient for releases.
To know more about API testing, you can refer to-
Conclusion – Almost all unit testing principles and techniques are relevant to the automation and automation engineers should leverage them as and when needed rather than only relying on the traditional automation methods.
Talk to our Test Engineers
Fast track your ecommerce monitoring
Need To Know the Best Practices For Continuous Agile Testing
Need To Know the Best Practices For #Continuous Agile #Testing
The Delivery Manager approached the QA Head – When do you stop testing? The Head replied – We never stop testing, it should be continuous we may put a ‘,’ to pause for a while but make sure to pick it again to near perfection. The day, we stop testing, means our product is going to be the history in the market. Even if your product is stable, we need to test it if it works with new browsers, new java version? We need to test it again to see if it could take up a load of new users. We want to deliver quality, and hence Continuity is the key, we do not deliver use-n- throw software.
That’s the power of Continuity!
So how do manage continuity? Is Continuous Agile a tough game? Let’s a take a sneak peek into the best practice’s that could help you gain control of Agile and keep it continuous –
Know Your Customer
Knowing your customer mindset is of prime importance, just for example if you are testing a bank app – How easy it would be for the user to log in who a layman is? In case he forgets his password, do they have enough information to retrieve his password? Or what kind of information could hacker use to hack the account? Is the password field allowing a ‘copy function’?
Get into the shoes of the customer and then design the test cases/test scripts.
Integration and Automation is the Key
For testing to be Continuous Agile, every piece of code checked in needs to be included in the build. The Build Automation needs to be integrated with Automated Deployments, Test Case Execution, Regression Results and Bug Tracking.
Automate Test Cases TestAutomation
Manual Test Execution is a thing of past! Automate your test cycles to speed up the processes and widen your coverage.
Execute Smoke Test post Deployment
A test suite consisting of some bare minimum test cases in necessary for QA to start on Functional, Regression Testing to ensure the environment stability.
Convert Business UseCases to Test Scripts
Get in touch with the product owners/business users and try to get the use cases that could be elaborated to test scripts.
Access Your Software Risk Appetite RiskBasedTesting
What could be critical for a business user? What are the features that for software should work seamlessly and any issues in that could be disastrous? Weigh your features as per the risk associated with them and devise a Risk Based Test Suite. Either you could assign a number from 1-5 [ 1 being lowest and five being highest regarding risk] to your testcases and then could create a suite. Or you can get help from your business users/ top level professionals to assist you with that.
Adopt Lean Testing LeanTesting
Lean Testing is a concept where the waste is identified at an early stage to maximize quality. Just, for example, your banking app gets a new feature – as a new icon. As a tester now how would you design your test cycle? Does it need to have all the functionality tested or may be few would do? Lean Testing is a process through which you can not only speed up your testexecution but also identify the processes, delays that could hamper your continuous Agile process and provide guidelines for improvement.
Follow Standards, QA Processes, Testing Pyramid
Processes are meant to help you achieve faster and transparent results, so it should be a good practice to stick to them. To work on the test execution, you could also take help from the TestPyramid model and based on your risk appetite could work on UnitTesting, UITesting TestAutomation or IntegrationTesting.
Change is Constant
Charles Darwin said – “It is not the strongest of the species that survive, nor the most intelligent, but the one most responsive to change.” Hence, there would be last minute changes, fixes, builds and processes, the important point is you being prepared for it?
Give some time to Exploratory Testing Exploratory Testing
You cannot automate exploratory testing but is an integral part of any QA cycle, allocate some time for its manual execution.
Continuous Agile Testing is a process that could provide you with maximum throughput when you are Continuous. As the quote says –
A phased approach to continuous delivery is not only preferable; it’s infinitely more manageable.”
– Maurice Kherlakian.