Lecturecast notes/ unit 9 reflection:

One useful tool I have learnt through this unit when testing Python code/debugging is through the use of the assert statement - with this you can test if a certain condition is true; if the condition is true, nothing will happen and the code will keep running, but if an event occurs where the condition is not true, an AssertionError will flag up.

Further reading

The paper by Smith and Robson (1990) provides a helpful outline on the issues that can arise from testing in Object-Oriented Programming. This is particularly helpful for me when thinking about testing for the upcoming assignment on writing the code for my driverless car UML diagrams. One important feature of OOP that can bring up issues through testing is when using inheritance – the paper includes potential problems such as when using regression testing on classes which contain inherited features as if the superclass changes features, this directly effects its child classes – this had led me to think more carefully about how I will implement my coding; such as when/if to use inheritance.

Another paper which has been helpful in looking at the way of testing in OOP is by Hourani et al. (2019) which provides a model to promote readability, understandability and re-usability of code which leads to benefits in testability. One aspect of their model they argue should be focussed upon is the number of lines implemented per method – this is also relevant to me for my assignment when considering removing irrelevant code in order to reduce complexity and to promote testability ease of use.

Furthermore, Reitz (2016) provides some useful tips for testing, including testing for each line/unit separately, while also making sure that the name of your test is descriptive so it’s clearer to you and others to see what exactly you are testing and wanting to prove.

E-Portfolio activities - Activity 4:

Extend the following program to test accuracy of operations using the assert statement.

        # Python String Operations
        str1 = 'Hello'
        str2 ='World!'

        # using +
        print('str1 + str2 = ', str1 + str2)
        assert str2 != 'Hello'
        assert str2 != 'World!'

        # using *
        print('str1 * 3 =', str1 * 3)

The output raises an AssertionError for the second assert statement since the variable str2 is equal to ‘World!’. Also, since an exception is raised by the failed assert statement, the program terminates and does not continue to execute the print statement on the next line.

References

Geeksforgeeks (n.d.) Python Assert Statement. Available from: https://www.geeksforgeeks.org/python-assert-keyword/ [Accessed: 7 July 2023]

Hourani, H., Wasmi, H. & Alrawashdeh, T. (2009). A Code Complexity Model of Object Oriented Programming (OOP). 2019 IEEE Jordan International Joint Conference on Electrical Engineering and Information Technology (JEEIT) (pp. 560-564).

Jacobson, I., Rumbaugh, J. & Booch, G. (2004) The Unified Modeling Language Reference Manual. 2nd ed. Pearson Education.

Pezze, M. & Young, M. (2008) Software Testing and Analysis: Process, Principles, and Techniques. John Wiley & Sons, Inc.

Reitz, K. (2016) The Hitchhiker’s Guide to Python: Best Practices for Development. O’Reilly.

Smith, M. D, & Robson, D. J. (1990) Object-oriented programming-the problems of validation. Proceedings of the Conference on Software Maintenance (pp. 272-281). DOI: 10.1109/ICSM.1990.131372.