5

I'm maintaining and testing a web-based timekeeping system written in Java. (It's a small IT shop, so I'm the only person working on it.) Employees use the system to enter the hours they've worked, request time off, etc.

I'm using Microsoft Test Manager to do some manual testing, but I'd like to automate it. Unfortunately, I'm running into a problem because of testing scenarios like this:

  1. Employee submits a request for time off on a certain date.
  2. Supervisor approves the time off request.
  3. Employee submits the timecard that reflects the absence on that date.

Automating this test presents me with 2 problems:

  1. When I want to repeat the test, entering the same date for the absence will fail validation, because the absence occurred in the past and that timecard has already been submitted. I suspect the best solution is to backup the test database, then restore it before each test. Is there an easier way?

  2. The validation code checks the current date and responds differently depending on when the requested absence is. For example, asking for time off next week is fine. Asking for time off way in the future results in a warning. Asking for time off way in the past is rejected. Is there a good way to handle this?

2
  • Microsoft Test Manager - is it some record/replay test tool with no way to i.e.generate current (today's) date or other valid dynamic values? Commented Jun 27, 2017 at 21:29
  • 1
    @PeterMasiar Microsoft Test Manager has some record/playback capability, but it's not really suited to automation
    – Kate Paulk
    Commented Jun 28, 2017 at 11:20

3 Answers 3

3

Regardless of the method you use to generate your request date, you're going to need to do this somewhat dynamically.

The simplest method is in the code to test each scenario, you do a call to get the current date, and then add or subtract days from it. You don't really care what precise date gets used in the request so much as that the response is what you expect it to be.

So in your tests I'd suggest something like this: (More or less structured English rather than code or pseudo-code)

[TestMethod]
RequestTimeOffInThePast()
{
  datetime Past = today().AddDays(-2)

  string Outcome = RequestDayOff(Past)

  Assert.That(Outcome).isRejected
}

[TestMethod]
RequestTimeOffNextWeek()
{
  datetime Soon = today().AddDays(7)

  string Outcome = RequestDayOff(Soon)

  Assert.That(Outcome).isAccepted

} 

[TestMethod]
RequestTimeOffNextWeek()
{
  datetime FarFuture = today().AddDays(400)

  string Outcome = RequestDayOff(FarFuture)

  Assert.That(Outcome).isGivenWarning

}

I've used variations on this method many times in automated tests where I needed to dynamically set or check expiry dates, creation dates, and so forth.

8
  • Perhaps I'm misunderstanding what you mean, but I don't think this works in my situation. I'm not talking about unit testing or some other coded testing. I'm using Microsoft Test Manager, so the testing is happening via the UI. In other words, "go to this web page, click that button, enter this value, click the next button", etc. It's all acceptance testing (or "functional testing" or "system testing" or whatever the proper terminology would be). Or is there some way to cause Microsoft Test Manager to calculate the input parameters? Commented Jun 27, 2017 at 20:17
  • @WallyHartshorn, you are looking at data-driven automated UI testing
    – Yu Zhang
    Commented Jun 27, 2017 at 20:43
  • 1
    @WallyHartshorn, please do not take my comment literally. data-driven automated UI testing is a general term. There are several tools that can do it for you, some of them are free. I have never used Microsoft Test Manager before, there is a chance you can do data-driven automated UI testing with MS Test Manager, but you will have to do some research.
    – Yu Zhang
    Commented Jun 27, 2017 at 21:13
  • 2
    Kate's answer is correct, it shows how to automate a date range based on today's date. She abstracted details to show the concept. Selenium can handle this easy if you have addressiblity to the date fields, just use the dates from Kate's code. Commented Jun 28, 2017 at 4:04
  • 1
    @WallyHartshorn - MTM isn't capable of the level of sophistication you're talking about. You can tell your test steps to use "yesterday", "next week", "next year", but it's not something you can automate with MTM.
    – Kate Paulk
    Commented Jun 28, 2017 at 11:22
1

Problem 1. When I want to repeat the test, entering the same date for the absence will fail validation, because the absence occurred in the past and that timecard has already been submitted. I suspect the best solution is to backup the test database, then restore it before each test. Is there an easier way?

Suggestion -

  • I dont think this would be good option to implement.
  • We should not reset our DB every time or for every single test. Please avoid.

Problem 2. The validation code checks the current date and responds differently depending on when the requested absence is. For example, asking for time off next week is fine. Asking for time off way in the future results in a warning. Asking for time off way in the past is rejected. Is there a good way to handle this?

Suggestion -

  • Its good to differentiate scenarios in 3 partition between Past, Today, Future dates requests.
  • You can manipulate date easily using different methods of Time class in Java.[Use third party gem/class for other language]
  • When we are doing any scenario for Past if you file on with one user, Then to repeat same scenarios we are having following options:
    1. Use different time stamp with same user [If possible]
    2. Use different user for each request [I am considering you know how to generate new user & unique email ids]

Note : As per my knowledge, User can update/add time booking many times in a day. So your functionality should be somewhat identical for market practices. If its not then I will suggest to communicate with you concerns team/lead. We should also understand whether this scenario is correct & can be automated?

0

Tests that need to traverse time to pass are often good cases for using tools that manipulate time.

For example with ruby and rspec there is the timecop gem that lets you both freeze and move time.

You'll need to set up the users in question of course and as with many other things that will be a 'before' step for each test.

Not sure if Microsoft Test Manager allows date/time maniplulation as I don't see it from searching.

For windows I do see

http://www.nirsoft.net/utils/run_as_date.html

and

https://solution-soft.com/products/time-machine

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.