Problem Description:
Import org.junit.Test conflicts with a type defined in the same file
There is a conflict between the imported org.junit.Test and an identical file
Problem code:
@Test Public voidTest ()throwsSQLException {queryrunner qr=NewQueryrunner (C3p0util.getdatasource ()); String SQL= "SELECT * from User"; //is based on the set and get methods//requires Setfoo () and field names in table Foo to remain consistent//beanlisthandler<> Wrapping Query results to an objectlist<user> users = qr.query (SQL,NewBeanlisthandler<user> (User.class)); for(user user:users) {System.out.println (user); } }
Problem Analysis:
The Java class that writes the JUnit test is named Test, and Org.junit.Test has a package that is class Test.class, which has the same name , and therefore conflicts
Problem solving:
Modify the class name
Summary of issues:
3.8 and JUnit 4, the former using reflection, the latter using reflection and annotations in use, need to introduce Junit.jar, and then the method needs to be tested directly using @test to indicate that this is a test method
Just introducing Junit.jar is not enough, the JUnit official package also contains Hamcrest,junit and Hamcrest are two different frameworks, different things, so these two packages are to be imported at the same time
When naming, be aware that the class name and package name are not directly named Test
A class declared as test using Org.junit.Test, with no return value, can be run directly without the Main method
Web Unit Testing