I'm new to software development and I am writing some functions that send data to and ask for data from a server. If I wanted to use test driven development when writing these functions, what would be the best way to go about doing it? The entire point of the function is sending data to/requesting data from the server, so obviously I should be testing to make sure the server is receiving the requests correctly and that the client is receiving data correctly. Should I attempt to get code implemented both client-side and server-side, to test the function output? With TDD already being a very time consuming way of developing software, having to implement code on both the client and server for every new test seems excessively time consuming.
-
Not sure why you consider TDD a "very time consuming way of developing software"? You are writing the tests anyway, TDD just suggests to write them first, not last. So time is the same. Do you really want to "save" time by not writing the test?– Peter M. - stands for MonicaCommented Nov 20, 2014 at 23:19
-
I meant more in terms of up front time investment, not overall time (that is, it takes my code a much longer amount of time to be produced, even if the eventual working product takes the same amount of time or less)– SamCommented Nov 24, 2014 at 17:28
-
In any case, I would still like to know if testing would involve implementing the test both Server-side and Client-side code, or does there exist a better way of implementing tests that might not require Server-side code to be written?– SamCommented Nov 24, 2014 at 17:30
1 Answer
Lets assume that you go with the TDD approach to writing your tests. In this case you should be focusing on writing tests for the code you are implementing. If in this case you are working on client side code that makes calls to a server you should be working with unit tests initially that test the calls you are making. Using stubs and mock objects you can impersonate the server interaction to build out the expected calls and responses you should get. Your will likely have a series of tests for the submissions and a series of tests for the responses.
The next step might be to build some integration tests that allow you to test the interactions between your client side code and the server. In this case you may have a test that wraps several methods and reflects how they work together. In this case the server is a bit of a black box. Assuming you get the responses back that you expect this gives lets you know that your code is playing nice with the server.