1

I'm working on a project that displays the possible transfers at the next bus stop for the own vehicle. Each transfer is accompanied by departure time in minutes.

Since the information is dynamic you might have already guessed that it is retrieved from a remote server, which (of course) I have no access to except sending GET requests and parsing the XML replies. Loss of connectivity is handled separately from the topic in this question. The main goal here is to create a dummy web server that will allow the tester to write new test cases and then run those against the application in a more realistic manner without the need to change the code of the tested software.

The onboard unit (the brain of the bus) generates several important pieces of information that are sent to the system that the software is running on - line number, course number and the stop ID the vehicle is headed to.

The stop ID is used as a parameter in a GET request to the remote server, which in return replies with an XML document full with journeys including own journey and both valid and invalid transfers.

After finding the own journey (based on current date, line and course number all of which are part of a unique ID for each journey) all other journeys go through a set of filters one of which calculates the departure time relative to the current system time and checks if the transfer isn't leaving the next bus stop BEFORE the own vehicle has arrived there (transfer time on foot is also included in this calculation).

As you can see there are two places where current time is of the essence (on the server side) and one - on the application side. I'm now in the process of setting up a dummy web server that will allow me to verify some of the features related to the data from the remote server (unit testing).

Normally (if data was not bound to the current system time) I would go straight for the good old "create XML files each covering specific case(s) and then load these one at a time". However due to the dynamic nature of the data and the filter(s) that are in place this approach won't do.

There are currently two solutions that I have come up with so far:

  • Given that the XML files I've just mentioned are present before each test run update these (all time-related data inside)
  • Generate XML replies on the fly and automatically adjust the time stamps in those - this has one big flaw namely that adding new test cases would involve writing new code

I find the second version more appealing because I would be able to integrate the generation of the XML data more tightly with my test web server.

Is this the better option? Are there other better ones?

4
  • I'm not sure I understood this - you're creating a mock web server to simulate the remote server's behavior? I don't want to give you an answer based on incorrect assumptions.
    – Kate Paulk
    Commented Feb 13, 2018 at 12:21
  • Yes, you understood this correct. Since I don't have access to the server's contents I need to mimic those. The dummy web server will also allow me to check for things related to the connection itself (such as timeouts or connection being interrupted). I've updated my question to clarify this. Commented Feb 13, 2018 at 12:35
  • Two questions. 1 - what is your testing goal (to test UI only or to test integration with backend)? 2 - can you pretend to be a bus and send the data which perfectly fits your test execution time using the same interface the buses do?.
    – Alexey R.
    Commented Feb 13, 2018 at 18:50
  • 1) The UI is not actually handled by the software I've described. Basically it's a module that sends information about the transfers to a core component, which respectively displays the information on the screen. So it's the backend that I need to test. As for 2)yes, I can do that. I've even created a tool that simulates the behaviour of the onboard unit and used it 70% of the development time since back than I didn't have access to the hardware. :P Commented Feb 13, 2018 at 21:07

2 Answers 2

3

I would handle this by a slightly different method, given that you are creating a mock web server.

Since the data you're retrieving depends so heavily on the time, I would use a mock/fake time service that returns predetermined times rather than the system time. That way you will be able to work with a deterministic known set of data rather than having to check the effectiveness based on shifting data.

This will also allow you to simulate your calls to the system coming from a variety of times, without having to worry about exactly when you make the call.

By setting the schedule in your mock web server to be the same each day, you can ensure you have a known data set to work with for each test.

You may need to tweak some things in your tests to set up a clean way to call the time service (it could be as simple as deciding on a correspondence between the minutes in the XML timestamp and the time the time service returns, such as 01 minutes in the XML => 10:00 AM from the time service)

6
  • Thanks for the reply. The problem is that the software itself also relies on the system time. As I've mentioned there is one filter in place that uses the time to make some calculations and then exclude part of the possible transfers. I even thought about freezing the system time of the system, where the software is running on, but this is not possible. Commented Feb 13, 2018 at 14:42
  • @rbaleksandar - you have two options: make time (and so system responses) deterministic by mocking that part of the system, or chose not to do that. Depending on your choice, your testing strategies will be different. Commented Feb 13, 2018 at 14:52
  • Right now I'm working on a possible solution namely I do use the current time, however all the transfers are adapted to it (for example: transfer 1 departs +30 after current time, transfer 2 departs -10 before current time etc.). Because time in itself (is it morning, afternoon or evening) is not important. It's the time difference that is and this can be done by using time deltas relative to the current time. I think... LOL Commented Feb 13, 2018 at 14:55
  • why isn't it possible to manually set the time on the server and client ?
    – Rsf
    Commented Feb 14, 2018 at 7:56
  • @rsf - it's possible, but it can cause other problems, and will likely get blown away as soon as the system syncs with a time server.
    – Kate Paulk
    Commented Feb 14, 2018 at 12:51
0

I'd lean towards generating the responses dynamically:

  • Not sure what you're using for your mock server, but if you use something like this, then you can generate your XML locally in your test, and then just make the request to the fake server to mock the response appropriately
  • I'd spend a little time generalizing out the common XML responses, writing utility functions for the cases I care to mock (thus meaning adding new cases is just a matter of calling these response generation utility functions, rather than writing a lot of new code)
1
  • The mock server is used to provide the XML data to the application, which needs to connect to a working server in order to work. Since I have no access to the real server, which makes testing stuff as difficult as possible, I need to have a mock server where I can generate my own data (and keep it constant; the real server provides different information all the time which makes re-checking an issue impossible in some cases or involves a huge amount of time to do so) and server it to the tested software to see how it reacts. I'm currently in the process of generalizing the common XML parts. Commented Feb 26, 2018 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.