Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

What I need to do is to create UI test cases for our application and we have decided to use Selenium with TestNG (we're still open to other options if there are considerable advantages).

The tests we are trying to create are tests where several users interact with each other using the application. Basically we need to have several users logging in in parallel into our application and perform different actions. There is a relation between the actions of the users so they need to synchronize their interaction in some points (e.g a user needs to wait that a different user performs an action before he can perform his action). This means that there also needs to have some sort of shared information between the users (I was simply thinking about sharing an object that will take care of the synchronization points).

How should I structure my scenario where I need to describe the actions of different users that will run in parallel using TestNG?

Is there a better framework for this or is there a pattern that addresses this problem? Any suggestios are welcome! Thank you.

EDIT:
The best I could thing so far is to create a test where each @Test method has the actions of each user and then create a Suite where I define that the test methods should run in parallel. Example:

public class MultiUserTest {
    @Test
    public void user1Interaction() {
        User user1 = new User();
        // user1 performs actions
    }

    @Test
    public void user2Interaction() {
        User user2 = new User();
        // user2 performs actions
    }
}

Then create a Test Suite where I specify that the methods of MultiUserTest should run in parallel.

However I don't really like this solution. I don't like the fact that I'm relying on an XML configuration (Test Suite) to describe the correct behavior of my test (which will not be obvious just by looking at the java code). I also don't like the fact that I will not be able to simply run the test by using the TestNG plugin on eclipse by doing "Run As - TestNG Test". Again, any suggestion is very welcome. Thank you!

share|improve this question
add comment

2 Answers 2

One possibility: Put each user's activities in a class (perhaps anonymous) that implements Callable. Then have your test method instantiate each Callable, invoke them using an ExecutorService, then retrieve the threads' results when they finish.

See:

  • Callable
  • Executors, especially the unconfigurableExecutorService() method.
  • ExecutorService to invoke the subthreads and retrieve their results and exceptions.
share|improve this answer
add comment

You can use testNG Dependency feature for this. This would make sure that your methods run in a predefined order. You are also not relying on XML configuration order. Plus it will run fine with testNG eclipse plugin also.

share|improve this answer
    
How can I use TestNG Dependency to achieve this? I don't want to run the methods in a predefined order, I want to run them in parallel. The solution I added to the question is very close to what I was looking for, the only problem is that the fact that I want the methods to run in parallel cannot be specified in the test itself (through an annotation, for example) so that the eclipse plugin would also pick it up and I would not need an xml file. –  Mario Duarte Jan 5 '12 at 15:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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