dimanche 31 décembre 2017

Integration testing with spark server

Hi im trying to IT my spark server. My intentions are to test all the controller functions. I have thought about few options: 1. Set up a server that will start when running the tests, and terminate when the tests are over.

The problem with this solution is that I have to rewrite my whole server logic to the new server (we start server from scratch every time we set the server before the testing).

  1. Initiate a controller from the test class (essential to initiate and not static call, in order to configurate the right db to the controller) that will call the controller functions and check their answers.

This is my favorite one, but it means that I have to mock a spark request. Im trying to build a spark request, and spark response objects, to send to my controller, and hanv't found a single way to do that properly (and how to send paramters, set url routes etc..)

@Test
 Public void testTry(){
   String expectedName = "mark";
   myController myCtl = new myController()
   Request req = null;
   Response res = null;

   String childName =      myCtl.getChildNameFromDB(req, res);

  assertEquals(childName, expectedName);
}

  1. The last one is to do the exact logic of the controler function in the test, and instead of getting the parameters from the request, ill initiate them myself. For example, instead of: String username = req.params(""usrName") It will be: Strimg username = "mark"

But that solution will demand copying a lot of code, and you might miss a little code line which might make the test succeed when in reality, the controller function fails (or doesnt deliver as wanted).

What do you think about Integratiom testing a spark driven server ? Im open minded to new solutions aswell, thanks!

Aucun commentaire:

Enregistrer un commentaire