Wednesday 1 April 2015

Week 10

So week 10 we focused on, basically, assuring that the code we write is performing exactly what we expect and not passing simple tests by sheer luck, that there is no flaw. So in order to do this, we first must identify good test cases until we are confident in our code, testing the boundaries, any special cases, different sizes if applicable, etc. in other words:

In this specific case, we expect the result to be x. Now run the code and see if you get x.

Of course that's just simplifying everything. To test it we can use 'assert' statements which basically allow you to test if x condition is true, the code is correct, else raise an error in a simple line. Not really difficult to understand but just know the syntax is kind of different:
 assert (condition), (error message)

In order to even be able to test anything you have to create all the applicable objects and appropriate circumstances to test a specific case. We can use fixtures which involve being able to easily create/remove the objects required in order to test each case.

Now I had previously interpreted that incorrectly in the sense that we can simply create the objects ourselves at the beginning of the class and make adjustments accordingly inside the test cases. But obviously that would be tedious with a lot of test cases so we instead use help to create separate instances easily each time to prevent the tedium.

 Once our code gets even more complicated, all you can do is really take it step by step and look over each individual line independently and as a whole. Know what it does and how it interacts with everything else. Unintended interactions, bugs will almost always be created and it's never easy to find and fix the minute subtleties in your code!

No comments:

Post a Comment