Junit Multithreaded Testing

Source: Internet
Author: User
Tags throwable

Because a new startup thread is equivalent to executing a method asynchronously, it is difficult to execute in unit tests.

After searching for data, there is a groboutils tool that enables multithreaded testing, http://groboutils.sourceforge.net/

A simple example fragment:

@Test public
    void Grobotest () throws Throwable {
        //Constructs a runner
        testrunnable runner = new Testrunnable () {
 
   @Override public
            void Runtest () throws Throwable {
                //test content
                System.out.println (Thread.CurrentThread (). GetName ());
            }
        ;
        int runnercount = +;
        Rnner array, how many you want to be in concurrency.
        testrunnable[] trs = new Testrunnable[runnercount];
        for (int i = 0; i < Runnercount; i++) {
            trs[i] = runner;
        }
        Runner for executing multithreaded test cases, passing an array of the previously defined single runner into
        multithreadedtestrunner mttr = new Multithreadedtestrunner (TRS);
        Develop concurrent execution of content defined in the array
        mttr.runtestrunnables ();
    }
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.