What is the best approach to write the automation test cases that run on particular instances of time?



  • My application has several jobs which runs 4-6 times a day and changes the system state and many configurations. Now I want to write automation test cases which will verify this state transitions and configuration changes accordingly.

    I have think two approaches-

    1. write some test cases and on particular verification steps I can add some precondition that this test steps should wait until 11am for example.
    2. Second is that I will use jenkins etc. and schedule my test cases for a particular time. In this approach I guess I will have to divide the test case to the smaller test case so that I can schedule one part to run in morning and other in noon.

    I am just willing to follow the best approach, these two came in my mind. Please suggest if there are some better approaches available.



  • I don't know about "the best approach" but I'd prefer a more continuous feedback way. If you introduce some form of timetravel in your tests / code that forces the environment to believe the time is something else, then you can test these triggers at any time continuously.

    This way however requires you to have access to the code or developer buy in to achieve.

    @Test
    public void shouldHateMondays() throws Exception
    {
        final TimeStub testTime = new TimeStub();
        testTime.setTime("sunday");
        MyTimeAwareApplication myTimeAwareApplication = new MyTimeAwareApplication(testTime);
        final Garfield garfield = myTimeAwareApplication.createGarfield();
    
        assertFalse(garfield.hatesToday());
    
        testTime.timeTravelTo("monday"); // constantly updates the time until it reaches destination to trigger all events
    
        assertTrue(garfield.hatesToday());
    }
    

    In this example I would wire in my special Time stub that i can control, while in production I would pass in a RealTime object. which would just query System.currentTimeMillis()


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2