Also, to get a full length course on power electronics simulations, check out my online course:
The class in the command line interface is:
The functionalities that I am testing for specifically are:
- Check whether an element is a component (could also be a wire), a jump label or no connection at all.
- A jump must be the extreme element in a branch segment. If it has components on more than one side, that is a violation that throws an exception.
- Two jump labels cannot be adjacent to each other - that is a violation that throws an exception.
- A jump label cannot be next to a node - a violation that throws an exception.
with pytest.raises(SystemExit): ...method...
So, the method or the block of code must throw an error or else the test fails. SystemExit could be replaced by other errors, but in this case, all I do is exit with an error code of 1 and so a SystemExit is all I can check for.
Conversely, if a method or block of code should not throw and error, the test can be written as:
try: ...method... except: pytest.fail('This should haved worked')
The class for the web app is a bit different:
The primary reason is that the web application does not exit with an error code when a violation takes place but merely displays the errors to the user on the web browser. So the check is for the result of the methods to be a non null list that would be an error message.
One major advantage of testing was that I found myself investigating code and thinking of possible ways that it could fail. It is a completely different form of coding as opposed to regular development where you are just trying to get the code to work. In testing, you are thinking of ways to break the code. This is a totally different aspect to development that can be fun if you look at it the right way.