Timeline for Unit test which asserts that current thread is the main thread
Current License: CC BY-SA 4.0
16 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 21, 2018 at 9:54 | comment | added | Vladimir Kaltyrin | I think it's an answer because when I look at the actual code I found out that there is an asynchronous call of the main thread. Thus, the assertation is called after the delay, which is unacceptable for the speed of the unit test. Asynchronous call of the main thread should be mocked, in this case, I can say that it will be a unit test. | |
| Dec 21, 2018 at 9:51 | vote | accept | Vladimir Kaltyrin | ||
| Dec 21, 2018 at 4:24 | history | edited | candied_orange | CC BY-SA 4.0 | added 186 characters in body |
| Dec 16, 2018 at 16:27 | comment | added | candied_orange | @coolpasta I never said every line of your code has to live up to my ideals. I'm just asking you to call a spade a spade. A test is a test. I'm certainly glad to have it rather than nothing. But running it with a unit test framework doesn't make it a unit test. Lumping it together with real unit tests damages those unit tests. You can give your other tests their own place to live. We have meaningful definitions for these things so people will know what we're talking about. If unit tests don't work for you fine. Don't use them. But please don't tell me I can't use them because you don't. | |
| Dec 16, 2018 at 12:37 | comment | added | coolpasta | I hate answers like this. OP didn't ask "What is a good Unit Test?". Owning a business and programming myself while trying to maintain a high level of readability is hard. The people I work with and mentor me worked with big systems where a fault could break everything. But it never does. I genuinely don't understand purists that need to feed their ego by tripping on semantics. Write minimally understandable and decopuled code, test for somewhat known cases - release, this amount of thorough testing is not needed and it won't come back to bite you, unless you have a monster in your codebase. | |
| Dec 16, 2018 at 10:41 | comment | added | Ewan | If the OP had said Integration instead of Unit they would still have the same problem | |
| Dec 15, 2018 at 21:36 | comment | added | candied_orange | The critically important thing is to segregate such tests. Mixing 1 slow test in a suite of 99 fast tests changes the way you can use the suite. I like to have a suite that is fast enough to run as I type. | |
| Dec 15, 2018 at 21:14 | comment | added | Fabio | @candied_orange, I would simplify to test is not a unit test if: 1. Slow, 2. Complex to configure (then test become integration test and unit test will use mocks). | |
| Dec 15, 2018 at 21:12 | comment | added | whatsisname | FWIW, tests that do 1-3 can still be quite useful and a unit test runner is a mighty convenient way to run such "untigration" tests. | |
| Dec 15, 2018 at 0:14 | comment | added | candied_orange | @opa testing the file is a fine test. It's not a unit test. I can run all my unit tests, multiple times, while you're still waiting on that one test. It's not dogmatic. It's the definition of unit testing. Maybe it's not for you. That's fine. But don't pretend you do it if you don't. | |
| Dec 14, 2018 at 23:26 | comment | added | Krupip | @candied_orange except when the logger only takes the filename it should output to as input. Point isn't that "Unit tests test units not the system resources" is wrong, it's 100% correct.You can't be so dogmatic as to say when tests touch file io that it is not a valid unit test. Testing a logger via reading its file output is way easier than making private functionality public just for the sake of unit testing, which you really should never do. It isn't testing the IO, it's testing the logger, it just happens the easiest way to do that is to read the file if you still want clean code. | |
| Dec 14, 2018 at 23:19 | comment | added | candied_orange | @opa If you need to test that you can do it by passing in your own stream. Unit tests test units not system resources. | |
| Dec 14, 2018 at 22:54 | comment | added | Krupip | @candied_orange So now you have to expose internal logic? Because how else are you going to separate the string generated by the logger before it is output to a file with separating it out into a private method? | |
| Dec 14, 2018 at 22:36 | comment | added | candied_orange | @opa if your logger has interesting business logic you isolate that and unit test it. Boring code that confirms we have a file system doesn't need unit testing. | |
| Dec 14, 2018 at 21:47 | comment | added | Krupip | How do you unit test a logger? Do you have to moc IO? That seems obnoxious. | |
| Dec 14, 2018 at 17:14 | history | answered | candied_orange | CC BY-SA 4.0 |