[This article is from the Sky Cloud-owned blog Park]Brief descriptionUsing JUnit combined with Mockito, coupled with some of the Spingframework's own methods, can be combined to test the controller layer in spring MVC.Before we design the test case, we have to take the logic of the controller's code in-depth and go through the drill-by-layer. The purpose of the walk-through is to identify the main logical b
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: Test, success, as s
These days in the SPRINGMVC project, now summarize some of the problems encountered during the test.Prior to the project, is in the newer MyEclipse (2013) above the MAVEN development, the Pom.xml file is copied directly, do the test time is relatively smooth. However this time, is in MyEclipse 8.5 above development, uses is JavaEE5, in the test time, has encountered many problems, sometimes quickly gets killed!In general, we give the test Class A single package, and also give
Today, I encountered a strange thing. I configured transactions in the Spring configuration file and performed transactions on all methods at the Service layer. However, when I tested one of the methods, it is found that it is not a transaction, and the first operation in it is completed, but the second operation fails. The reason is found. It turns out that the try and catch statement blocks are used inside this method, so that exceptions are caught
Time: 2017-2-2-02:23Steps:1. There are junit environments in the program2. Import Jar PackageSpring-test-3.2.0.release.jar3. Add annotations4. Sample CodeImport Org.junit.test;import Org.junit.runner.runwith;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.test.context.contextconfiguration;importOrg.springframework.test.context.junit4.SpringJUnit4ClassRunner;Import Com.wyc.service.UserService; @RunWith (Springju
Spring-test using JUnit, the test class uses autowired to make an error,Report Create Bean Error ...But the controller inside @autowired can run normally.Ask questions on the Internet and confirm that I must have a problem with the scan package. But the controller inside is clearly can get AH.Wait, I'm building a project using MAVEN, and the project is divided into main, test two parts. The configuration fi
When the configuration file contains two spring datasource, the following error is reported during spring JUnit testing:
Nosuchbeandefinitionexception: no unique bean of type, expected single matching bean but found 2 [performance1, performance2]
The annotation of the test class is as follows:@ Runwith (springjunit4classrunner. Class)@ Contextconfiguration (l
Using the spring framework to make it easy to write code with separate tests for some code snippet code without having to run the entire environment for testing, the JUnit test is introduced to facilitate the testing of the local code block.1, first guide package, such as MAVEN project: where JUnit needs at least in the 4.12 version, or will be error 2 Create a
Examples are as follows: Packagecom.junge.demo.spring;Import Staticorg.junit.Assert.assertEquals;Importjava.util.List;Importorg.junit.Test;ImportOrg.junit.runner.RunWith;Importorg.springframework.beans.factory.annotation.Autowired;Importorg.springframework.test.context.ContextConfiguration;ImportOrg.springframework.test.context.junit4.SpringJUnit4ClassRunner;ImportCom.junge.demo.spring.service.IPerface;ImportCom.junge.demo.spring.service.ServiceConfig;/*** Unit test for simple App.*/@RunWith (Sp
The most recent use of the DAO injected by the JUnit Test Spring produces a strange javaw.exe error that needs to be closed.
At first I thought it was the configuration file or the code was wrong, but the check did not identify the problem. So sent to a friend that implementation, his computer on the implementation immediately green, depressed 2 days also can not solve, should be aware of the problem of th
Testing the controller layer in SPRING-MVC is generally cumbersome because there is no such context in the Web container, and it is not elegant to start the container test. Maven dependency, which needs to be noted is the use of Spring-test-mvc, such a framework. Slightly different from the normal spring test is an annotated @WebAppConfiguration, which uses the
Directly on the code package dependency please add your own Maven added dependency is very convenient1, Testbase.javaPackage Com.test;import Org.apache.commons.logging.log;import Org.apache.commons.logging.logfactory;import Org.junit.before;import Org.junit.runner.runwith;import Org.springframework.test.context.activeprofiles;import Org.springframework.test.context.contextconfiguration;import Org.springframework.test.context.junit4.SpringJUnit4ClassRunner, @RunWith (Springjunit4classrunner.class
. "[, \\s]+" is a regular expression, \\s represents a variety of whitespace characters, + means matching more than one.)* StringUtils is a tool class for manipulating Java.lang.String under Org.apache.commons.lang,* Use may require manual import of Commons-lang-xx.jar* Split the Springxmlpath path apart,* Because the Springxmlpath path may be a concatenation of multiple paths, the XML under each path will be scanned for recognition after splitting*/context = new Classpathxmlapplicationcontext (
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.