JUnit unit tests do not respond to thread testing

Source: Internet
Author: User

Today also want to write a simple thread of things, the results have just finished writing I was crazy.

As a result, nothing is output, and the main method can be used to run the output. No way, only for years to find their own answers.

As a result, I have an understanding of all aspects.

First take a look at the code

Package com.mendale.test;import Java.util.date;import org.junit.Test; Public classTest1 {@Test Public voidTest () {MyTime Mt=NewMyTime ();    Mt.start (); }         Public Static voidMain (string[] args) {MyTime Mt=NewMyTime ();    Mt.start (); }}classMyTime extends thread{ Public voidRun () {Boolean flag=true;  while(flag) {Try{Thread.Sleep ( +); } Catch(interruptedexception e) {e.printstacktrace (); } Date D=NewDate (); System. out. println (d); }            }}

If you use unit tests you will find nothing to output, and no error; This time you're testing the main method, you'll

The discovery unexpectedly has the output, unexpectedly has the output!!! This problem also made me struggle for a long time.

Recall:

The method we use is actually an elf thread (that is, the daemon thread: it is guaranteed to run after other threads have finished running and then over). and unit tests I

Surfing the Internet. It's not an elf thread.

(Subsequent source analysis: suspended)

JUnit unit tests do not respond to thread testing

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.