Perfect solution to import org.junit.Test and @Test errors --- Solutions

The import org.junit.Test and @Test errors have been resolved—Solutions

insert image description here

Article Directory

Error report

A friend in the fan group reported an error when he typed the code (at that time, his heart was cold for a moment, and he came to me for help, and then helped him solve it smoothly. By the way, I hope it can help more people encounter this bug. Friends who will not solve it), the error message is as follows:

When I used the spring framework to do projects recently, I found that import org.junit.Test and @Test reported errors from time to time. On the premise that the package did not import errors

insert image description here

Solution

The solution is as follows

insert image description here
Solution one:

MyEclipse right-click the project properties and select [build path] [add Libararies] interface, select JUnit import, Eclipse is the same.

Solution two:

The reason is that the package where the java file is located is the default anonymous package.
Create a new package with a name of com.XXX.XXX, and move the java file to this name and it will be ok

Solution three:

The java class for writing junit tests is called Test.java. If you must use Test.java, you can only add @ org.junit.Test to the method

Solution four:

Try not to use Test as the class name of the test class, and change it to another class name. I have encountered this problem many times, and it is because the class name is Test. After the change, no error is reported normally.

Welfare

6 technical books will be sent home with free shipping every week.
Due to the limited time and energy of the blogger, there are too many private messages every day, and there is no way for every fan to reply in time.
You can enter the community skirt or add the blogger WeChat
and click the link below
http:/ /t.csdn.cn/6kInJ

Guess you like

Origin blog.csdn.net/weixin_50843918/article/details/130694138