In the previous versions of the ISBN Validation Exercise, I had the “test” code embedded with the actual validator itself. For simplicity, I think this is was the easiest way for the author to present the exercise on Codementor. As a reminder, this is what the “inline” test code looked like:
def test_isbns():
isbn = "123"
assert ISBNExercise.validate_isbn10(isbn) is False
isbn = "0136091814"
assert ISBNExercise.validate_isbn10(isbn) is True
isbn = "1616550416"
...
Generally, it isn’t considered good design practice to embed testing code inside of an application, and since I’m getting a bit carried away with this example, I figured that I’d do a bit of refactoring to add a more robust series of tests using the Python unittest
framework. For those of you who aren’t familiar with the concept of unit tests, or why they are helpful, there is a great post at RealPython that explains the concept, as well as how to use the unittest
framework in Python.
…
ISBN Validation: Adding Simple Python Unit TestsRead More »