Most introductions to unit testing give very simple examples of functions that simply receive some arguments and produce a result. However a lot of software has to read input from external sources, such as from the internet, from the file system, or from the user during its execution. How does one write tests for such software?

For simple software that only reads a few files from the file system, I imagine can be tested by writing some files for the test to give to the tested program, but what if it becomes more complex? Or what if you are trying to test a web scrapper for a website, would the tests run a web server and simulate the targetted website? Or for the GUI, how would one test that the user can see what they are supposed to see, when they click a certain way at a certain time?

Maybe the parts that read the data shouldn’t be tested and only the functions that code relies on should be tested? I don’t know.

  • BaconIsAVeg@lemmy.ml
    link
    fedilink
    English
    arrow-up
    2
    ·
    11 months ago

    There’s unit tests like you’ve mentioned, but that’s only a part of the picture. What you’re describing is functional testing. Usually you want the backend unit testing, along with a framework to do API testing, and then frontend testing using browser automation (selenium, gauge, etc) depending on your needs.