Comment

Comment by byby

I think you don't understand what unit testability means. It means removing IO and side effects from your code.

How the hell do I test a print function? I take the print function and match it with what? It has no output so how can I test it printed the correct thing? I can't.

I can test a list. I just match it with another list. Making your code unit testable is about segregating IO from logic. Write pure logic where all functions have inputs and outputs and those things can be tested. Your io prints should be small because all functions that do io cannot be fully tested.

IO is pollution. Any output to IO is the program exiting the logical mathematical universe of the program and that output can be verified only by an external entity. Either your eyes for stdout or another process or files or a bunch of other ways.

Unit tests are about internal local tests that touch local functionality and logic. If you want something unit testable it needs a local output and an input and it shouldn't rely on io in it's data path.

I think your complaint here is an example of chatGPT superiority. It understood something you didn't. Well now you know.

Removing the print function from the logic and returning the data is 100 percent the correct move. Do you understand?

parent byby 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton