-1

I recently finished developing a piece of software in python where learning models and data processing procedures are contained within different class objects that succeed to each others (modules). As I'm new to standard practices in software development, I would like to know the followings:

  1. Should I apply unittests to all my modules (and relate methods) to make sure that any future changes will be checked thereafter?
  2. Should I develop assertion/exception tools that check the user inputs of all modules (and related methods) and raise errors if e.g. an input value is not within an expected range?

The final goal will be to develop a web-based app (with deployment and monitoring of learning models).

1 Answer 1

5

Unit tests or range checks are not added to a software because "there exists some standard practice or law in softwareengineering" saying you must do this.

Unit tests are added because you want to achieve a certain level of maintainability and protection agains regressions. Sometimes unit tests are added because they are the most simple and quick approach to run, test and debug components. Range checks (and similar checks of user input) are added because you want to achieve a certain level of security and user-friendlyness (not telling users the reason why their input produces nonsense output can be pretty annoying). And when unchecked user input might influence a program to a degree where it behaves in a unforeseen manner, this can become a security issue.

Both tools require certain extra efforts to write some extra code - but both can also save efforts: unit tests can safe a lot debugging time, and range checks with clear error messages can safe a lot support time.

So it is up to you to decide this, depending on the cost/effort relationship and requirements for your specific system, which depend on overall context, like the intended life cycle for your program, or the number and kind of users.

2
  • Well, unit tests should not be added to software because of some "standard practice". In my experience, unit tests often are added either because of some cargo cult "more unit tests means better code" or because some architect in an ivory tower has specified a code coverage percentage. Commented Oct 23, 2022 at 16:30
  • 1
    @PhilipKendall: I am sure for almost any useful practice in software engineering you will find a place somewhere over the world where this practice is overused or underused.
    – Doc Brown
    Commented Oct 23, 2022 at 17:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.