This article turns from Http://www.tuicool.com/articles/7rMziyUsually to JUnit test Service/dao layer is already very familiar with, if not understand, can poke here, but we want to test controller layer, not always restart the server bar, (restart Tomcat good slow drift over, don't ...) Don't go), then we'll test the
After the configuration is successful, you need to start the test case!
Package com. CMC. controller;Import javax. annotation. Resource;Import org. junit. Test;Import org. junit. runner. RunWith;Import org. springframework. test. context. ContextConfiguration;Import org. sp
. Class) to specify that the runtime runs tests
Parameterized run test class
@RunWith (value=parameterized. Class)
Run as test suite
@RunWith (Suite. Class)
@SuiteClasses ({test1.class,test2.class,...})
@Parameters Cosmetic method to return test parameters
@Parameters
Public Static Collection Preparedata () {
object[][] data = {
{1,10,10},
{2,4,2},
{5,15,3},
{
but In:org.springframework.context.support.GenericAppliactionContext ............A similar problem has been found on the web, saying that it is possible to remove the static resource directory associated with the assert in the configuration file. It doesn't feel good, because it's no problem to start the project in Tomcat.Just started with JUnit, not quite familiar, and later thought that the JUnit configu
Generate test reports using the JUnit and ant that comes with eclipse1. Click the project you want to test, right-click, select Export2. On the pop-up page, click General, select Ant Buildfiles, click Next3. On the next page, select the project you want to test, fill in the Ant profile name, Build.xml,
Recently in the construction of Maven+springmvc+hibernate project, normal startup Project when everything is normal. However, the JUnit test was reported classnotfoundexception error, after careful investigation found that no class file generated.Now the solution is for example the following:watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmde2mta4mg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/
that JUnit can then look for the test class inside, and always find the testing case that can be executed and execute it.9. There are two ways to test a private method of a class:1) Modify the access modifier of the method to modify private to default or public (but this is not recommended).2) Use reflection to invoke the private method of the target class in th
ImportOrg.junit.runner.RunWith;Importorg.springframework.test.context.ContextConfiguration;ImportOrg.springframework.test.context.TestPropertySource;Importorg.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;ImportOrg.springframework.test.context.junit4.SpringJUnit4ClassRunner;/*** Created by JECYHW on 16-5-12.*/@RunWith (Springjunit4classrunner.class)//using spring to integrate JUnit test
First, the introduction of the Spring Test package: Text PackageIi. @RunWith: Specify a runner that spring provides to JUnit@ContextConfiguration: Locations specifying the Spring profile location1@RunWith (Springjunit4classrunner.class)2@ContextConfiguration (locations={"Classpath:ApplicationContext.xml"})3 Public classTestSpring1 {4 @Autowired5 PrivatePersonservice PS;6 @Test7 Public voidtest1 ()
In JUnit tests, it is sometimes necessary to obtain the name of the class or method to which it belongs, so as to make it easier to log something.
The TestName class is provided in JUnit to do this, in Org.junit.rules:
public class TestName extends Testwatcher {
private String fName;
@Override
protected void starting (Description d) {
fName = D.getmethodname ();
}
/**
* @return The name of th
It's been a long time since JUnit was tested, and today, using JUnit tests under the spring framework.I looked up some information on the Internet to find that my project is missing some jar package, now put this jar package information up, so as not to forget laterJUnit test, using in spring
The situation of the problem is as above.The solution to the problem is to check the entire line of the function instead of just the function name, as checked to run the JUnit test.Testmysql.testdrivermannager1unrooted TestsInitializationerror (Org.junit.runner.manipulation.Filter)Java.lang.Exception:No tests found matching Method testDriverMannager1 (testmysql.testmysql) from [email protected] At Org.junit.internal.requests.FilterRequest.getRunner (f
Using JUnit to test an example of a spring static factory instantiation Bean, all the code is fine, but there is a java.lang.IllegalArgumentException exception,As shown in the following: began to think that the code is wrong, find out, the code is not a problem, the original JDK version is too high, modify the JDK version of the project, reduce the version from 1.8 to 1.7, as shown in:
When using JUnit for testing, it is sometimes necessary to invoke HTTP communication, whether it is a request or a response or a session, then how to invoke in the test class, in fact, it is very simple, Spring provides us with three classesOrg.springframework.mock.web.mockhttpservletrequest,org.springframework.mock.web.mockhttpservletresponse,org.springframew Ork.mock.web.MockHttpSessionUse the following:@
Previously, Hibernate object classes and their ing files were put into the project. Since multiple projects use the same database, the Hibernate object classes and ing files are duplicated, which is not easy to maintain and upgrade. Therefore, extract it, compress it into a jar package, and introduce it back to the project.
In practice, a strange problem is found: The project runs normally, but the JUnit unit test
environment for each test case, first create a parent class: Basictest, the content is simple, really simple:@ContextConfiguration (locations= {"classpath:spring/applicationcontext.xml"," classpath:spring/spring-servlet.xml"})publicclass {}@ContextConfiguration: As the name implies is to configure the address of the context configuration file, I here is the Web program, so also to Spring-servlet.xml.There is already a @runwith on the Abstractjunit
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.