4 ms·
Those methods are still data in, data out tho right? So test that with mocked data. Unit tests should be able to run with no network connection, no other serv
by abritinthebay 9y ago
Those methods are still data in, data out tho right?
So test that with mocked data.
Unit tests should be able to run with no network connection, no other service, just your test file + data.
Otherwise at that point you’re doing integration testing, not unit tests.
- emilsedgh 9y agoLet's say I have a `SomeEntity.get` function. Basically it gets an array of id's and calls the database and fetches those entities. ~10 lines of Javascript code. 40 lines of SQL. Which also depends on the state of the database. So what do I gain by mocking the database? Making sure those 10 lines of javascript work fine? In a vacuum? They are the 10 easy lines anyways which are covered by my E2E test. What matters is the SQL and how it behaves in different states of the database.
- abritinthebay 9y agoAnd that’s why you test the DB with an integration test (and likely a functional test too). For your unit test you’d just mock the dB call and make sure that function called the “db” and returned the faux data. That’s it. No one said unit tests had to be complex or test the whole stack. Quite the opposite actually.
- filleduchaos 9y agoAt that point, that's just testing for the sake of testing, which is just silly - nobody needs you to prove that the compiler/interpreter/library/framework in fact works the way its maintainers have already tested it to work
- abritinthebay 9y agoYeah, the most you should be testing there is “it’s a function and it calls the (mock) db and returns data of type whatever”. That’s like... 2 minutes of test writing, tops? I think that we really need to discuss unit testing as a group more. Specifically: what a unit test isn’t. It’s amazing how popular some misguided and ill-informed ideas about them are...