Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Scout Tests with Timeout(Testing)
Scout Tests with Timeout [message #1386918] Mon, 23 June 2014 06:03 Go to next message
Rainer N. is currently offline Rainer N.Friend
Messages: 9
Registered: January 2014
Junior Member
Hi,

I am wondering whether it is possible to run Scout tests and to terminate them automatically if the are still running after a certain timeout.
I am using server tests with the ScoutServerTestRunner.

The JUnit Annotation @Test can be used with the parameter "timeout":
@Test(timeout = 100)
public void test() {}


However, the timeout declaration causes JUnit to run the test in a new process and consequently the code in the testcase is not running in a Scout transaction.
Starting a ServerJob with ServerJob.getCurrentSession() does not work either because getCurrentSession() returns null.

Is there a way to run such tests in a transaction?
Thank you.

Regards,
Rainer
Re: Scout Tests with Timeout [message #1395719 is a reply to message #1386918] Mon, 07 July 2014 09:44 Go to previous message
Rainer N. is currently offline Rainer N.Friend
Messages: 9
Registered: January 2014
Junior Member
I found a solution to run such tests:
The testing logic must be wrapped within a ServerJob.
As ServerJob.getCurrentSession() returns null, an own server session must be instantiated.

  @Test(timeout = 5000)
  public void testTimeout() throws Throwable {

    TestJob job = new TestJob() {

      @Override
      protected void executeTest() {
        //Testing logic with assertions
      }
    };

    job.runAndCheckAssertions();
  }

  abstract class TestJob extends ServerJob {

    private Throwable m_throwable;

    public TestJob() {
      super("Test", new CoreProductServerTestSession());
      m_throwable = null;
    }

    @Override
    protected IStatus runTransaction(IProgressMonitor monitor) throws Exception {
      try {
        executeTest();
      }
      catch (Throwable t) {
        m_throwable = t;
      }

      return Status.OK_STATUS;
    }

    public void runAndCheckAssertions() throws Throwable {
      runNow(null);

      if (m_throwable != null) {
        throw m_throwable;
      }
    }

    protected abstract void executeTest();
  }


CoreProductServerTestSession is a class implementing IServerSession.

[Updated on: Mon, 07 July 2014 12:13]

Report message to a moderator

Previous Topic:HTTP 500 error
Next Topic:Luna technologie RAP Filechooser problem
Goto Forum:
  


Current Time: Fri Apr 26 14:19:07 GMT 2024

Powered by FUDForum. Page generated in 0.02612 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top