I have a basic REST API in a server file. If I want to run tests on the routes, how do I do so?
I can think of 2 ways to do so:
In the test command, first start the server using a child process and then send requests to
localhost
in the unit tests.Write unit tests for all the functions I've written in my code and run them without running the server (Does this mean I can't do integration testing?)
I'm really not sure what to do, I need help.
Top comments (10)
Did you have a look at Postman? It's a really helpful tool for testing your API. It enables you to do integration testing
And don’t forget Postwoman
Tests
Well, I use Fastify most times for APIs and it has a nice method called
inject
, which is mostly just used for testing. The setup ends up looking something like(note: roughed most of this from memory so it might not be 100% runnable).
Otherwise
Most people use something like Postman. I've switched over to the Insomnia REST client.
The good alternative to Postman is a TestMace. I liked the way they looking at the testing environment as a filesystem project, so you can easily version control it and share across your team.
What language are you using?
I'm using Rust (for learning purposes)
ah ok - have a look for a rust-alternative to supertest (Javascript) or net/http/test (Go).
Yes it does.
Yes, take a look at the history and collections tabs.
Make a request, and click on the 'Save to collections' button (it looks like a disk).
Check my blog article about Requester (A sublime add-on). dev.to/ajeebkp23/requester-modern-...