30 ms·
I'm finding that the same things that make good regular code, make good testing code as well. Regardless of which layer you are testing(unit, integration, func
by aero142 17y ago
I'm finding that the same things that make good regular code, make good testing code as well. Regardless of which layer you are testing(unit, integration, functional), it is important to write a testing API. If you have a bunch of copy, paste, change one line unit tests, it is going to be very difficult to change an API. However, if you have one API call, "go and do this thing high level thing", then when the underlying API changes, you just change the implementation of that one API level function. The tests end up more readable as well because they read like english. "Setup a basic environment that looks like this." "Change the behavior of the one thing I am testing." "Validate the response".
If you are writing functional tests, the same thing applies. For a UI, you might have an API that reads like. "Go to the home page." "Create a User". "Login". "Go to the page I want". "validate this one behavior".
Since all tests are using an API, you just change the implementation of the API call. For example, if I change the number of fields required to login, I only have to change the login API call. For all the tests that used it, they don't care about how you login, because that wasn't the thing they were trying to test. It was just a pre-req.