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)