Testing in Python – KnowHows
This is the first part of the series ‘Testing in Python’.
In this first part am explaining very basic fundamentals of Testing in Python. So let’s have a look..
————————————————————————————————————
For basic concepts of Python, kindly visit series– Python Chapters
————————————————————————————————————
Testing
Showing and looking for errors can be hard because it’s always easy to show that there is something in spite of showing that there isn’t something. But that’s what we really want to do, whenever we talk about testing. So let’s have a look at testing goals.

Goals
– Show that bug exists.
– it would be great if we can prove that code is bugfree. 
Hurdles
– In real life, we can’t run all the possible test cases.
– Timeconsuming (generally.) 
Approaches
– Some generalized test cases.
– Formal methods or we can say mathematical approaches.
Test Suits
In test suite, we do try to find a set of inputs that has the very high likelihood of getting success or we can say revealing bugs.

How to?
– Partition of input subsets that provide equivalent information about correctness.
– Partition of inputs into subsets must be like each element of set exactly into one subset.
– Constructing the Test Suits, that have exactly one input from each partition (subset)
– Run all defined test suits.

Example (PseudoProcedure)
1. Suppose we want to find biggest of two number. So..
→ def isBigger (A, B):2. Now for this functionality, our assumptions will be like..
→ Assume A and B are int and returns ‘True’ if A is less than B. Otherwise ‘False’.3. Getting all possible inputs Input Space.
→ All* pair of inputs.4. Getting all the possible test cases.
→ A positive, B negative
→ A negative, B positive
→ A positive, B positive
→ A negative, B negative5. Plus, some more additional cases. Such as..
→ A = 0, B = 0
→ A != 0, B = 0
→ A = 0, B! = 0)

Why Only These 7 Cases?
You can have several other cases. But if you will look closely then you will get to know that all these cases are enough to tackle down all other cases. For example:
→ If you are thinking of a case – A is prime, B is not.
(This case is irrelevant because there isn’t any use of it.)
→ If you are thinking of a case A = 2.5, B = 2.0.
(This case is irrelevant because we have assumed that both A and B are integers.)
→ You can have lots other cases in mind. But if you will look closely you will find either they will be irrelevant or can be tackled down from our 7 cases. Meanwhile, if you still managed to get some then update me.
Partitioning
We have talked lot about partitioning and how it works? ..can be done etc. Now, it’s time to think about a bit awkward situation. Yup bit awkward.
What if there is no available natural partition to the input space?
In this situation, we still have three testing options. These are..

Random Testing
The base of this type of testing is the probability.
The probability that code is correct increases with the number of trials. But we should be able to use the code to do better.

BlackBox Testing
This approach uses the heuristics based on exploring paths through the specifications.

WhiteBox Testing
This approach uses the heuristics based on exploring paths through the specifications.
That’s all from Testing in Python (This Part). Keep visiting for upcoming articles in this series.
Till next, Keep Sharing & Tweaking and don’t forget Learning. 💡 💡
I was just looking at your Testing in Python – KnowHows and i found it very useful and unique. Waiting for more to come.
Hey, thanks. I’ll update some more stuff on that very soon and the next part will be BlackBox testing. Hoping to gt some reviews on that as well. Cheers! 🙂
I truly appreciate this post.
Hey,
Thanks man! 🙂