JUnit Basic Learning-multithreaded testing (6)

Source: Internet
Author: User

Steps:

1. Define a single Testrunner

2, overloading the single Testrunner Runtest ()

3. Define the Testrunner array and add multiple Testrunner

4. Multithreadedtestrunner Test

1 @Test2       Public voidmultirequeststest () {3            //Step One: Construct a runner4Testrunnable runner =Newtestrunnable () {5 @Override//Step two: overloaded Runtest function6              Public voidRuntest ()throwsThrowable {7                     //Test Content8Request.setrequesturi ("/postdoctors/usercontroller/selectuserbyid");9Request.setmethod ("POST");Ten                       One                       Try{ A                           -                          FinalModelandview Mav = Usercontroller.selectuserbyid (1, request, response); -Modelandviewassert.assertmodelattributeavailable (MAV, "map");  the                           -}Catch(Exception e) { - e.printstacktrace (); -                       } +                 }  -             };  +             intRunnercount = 100;  A            
Step three: Define an array at //Rnner Array, how many you want to be in concurrency. -Testrunnable[] TRS =NewTestrunnable[runnercount]; - for(inti = 0; i < Runnercount; i++) { -Trs[i] =runner; - } -
Step four: Multithreadedtestrunner test in //The runner used to perform multithreaded test cases, passing an array of the previously defined single runner into -Multithreadedtestrunner mttr =NewMultithreadedtestrunner (TRS); to Try { + //develop concurrent execution of content defined in an array - mttr.runtestrunnables (); the}Catch(Throwable e) { * e.printstacktrace (); $ } Panax Notoginseng}

JUnit Basic Learning-multithreaded testing (6)

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.