How do I learn Spring MVC

Junit4 device test test for Java programmers, it is very convenient and can do some basic testing.

First the first

<junit.version>4.12</junit.version><!-- test start --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency>

2. Declare a Foundation SpringTest, plus @Transactional annotations in the class so that the test class of that class is inserted, complete the test, and roll the database without affecting the existing data.

package com.ctp.ghub.junit; import org.springframework.transaction.annotation.Transactional; /** * Created by Administrator on 2018/5/21 0021. */ @Transactional public class BaseSpringTest {} 3. In the appropriate project directory add a test class that mainly test the DAO layers, @ Runwith is that the test is carried out in the Spring test environment in the Spring test environment, @ contextconfiguration is the configuration file of the database. import java.util.List; import com.ctp.ghub.dao.LogDao; import com.ctp.ghub.junit.BaseSpringTest; import com.ctp.ghub.model.LogDO; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author chengtianping * @description * @date 2018/5/22 */ @RunWith (SpringJUnit4ClassRunner.class) @ContextConfiguration ({"classpath: jdbc / common-jdbc.xml"}) public class LogDaoTest extends BaseSpringTest {@Autowired LogDao logDao; @Test public void testListAllUserDO () {List logDOList = logDao.listAllLogDO (); Assert.assertNotNull (logDOList); Assert.assertEquals (logDOList.size (), 1); }}

4. RUN, REACH, RUN or Debug