Hi Friends,
Today, in this discussion, we’ll discuss more about testing rather we’ll delve in automated testing and understand why it is mandatory for software development process. If you are following AGILE model in software development, then you might be knowing that client always focuses on testing of existing features plus the new features which is getting developed. Writing good test cases and meaningful test cases which are covering your code end to end gives you confidence that you have written robust code which won’t fail in any circumstances. Now, let’s understand some of the strengths of the Automated Testing.
- You can run these test cases any time
- Very quick while running
- You can run them again and again
- Also it relies on logical assertions.
Now, Let’s look at the different type of Tests.
- Unit Test:- Unit Tests are about testing your logic in small chunks rather testing your logic in isolation.
- Integration Test:- Means testing things together.
- User Interface Tests:- So, these tests execute via UI and testing things at user like behavior of the application when load increases likewise.
So, now without wasting time, let’s begin our discussion with Unit Testing:- So, as I said that Unit Testing is all about testing the thing in isolation. So, basically unit test focuses on the behavior of class like how it will be utilized by other classes. So, it makes one thing very clear that we’ll test only public API, we won’t test private methods. So, private methods or behaviors will be tested via public class members once it is exposed to it. So, ideally unit testing is best for testing complex and detailed behavior. Now, it also help us to catch the defect at the lowest level itself. Now, let’s check few best practices of writing Unit Tests.
- Testing Boundary Values:- Obviously, whichever testing book you refer, they will stretch upon this point.
- Happy Path and Negative Test cases:- Write test cases for both scenarios and test them equally.
- Find a bug and Write test case to fix the same.
- Write Test cases to test almost every part of your code
Now, basically Tests are divided into 3 fundamental Units. They are:-
- Arrange:- Under this we basically create an instance of class being tested. If it requires any kind of initialization, we’ll also do it here.
- Act:- In this stage, we will call the functionality which we are interested in testing.
- Assert:- In this phase, we basically compare our outcomes with expected behavior, based on the outcome, we come on conclusion whether test passed or failed.
Testing Frameworks:-
Now, Testing Frameworks basically provide a platform to write your tests, organize them, then provides the ability to do assertions on the test result. So, the test code which we write will use this framework and use testing attributes and assertion methods. Now, associated to this, there is one more concept which is closely related, often designated as “Test Runners“. So, a test runner will understand the framework being used, it will locate, enumerate and run tests for us. It will also give the snapshot of these tests in different flavors. Below i have mentioned few of the available Testing framework under Microsoft ecosystem:-
- MSTest
- xUnit.Net
- NUnit
Now, below is the screen shot for the same which is having the reference for testing framework in my solution. Now, here i will be using Microsoft Testing Framework for running my tests.
I’m wrapping this session here itself. In the next session we’ll start doing Demo with test classes and Test Methods. So, till then stay tuned and happy coding.
Thanks,
Rahul
Happy Coding