Web Unit Testing

Source: Internet
Author: User

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

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.