Java 测试代码模板

时间:2023-03-08 16:57:08

package com.robert.service;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
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;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.context.WebApplicationContext;

/**
* Created by robert on 2016/10/14 0014.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(“classpath*:ApplicationContext.xml”)
@WebAppConfiguration
public class LoginTest {

private Log log = LogFactory.getLog(LoginTest.class);

@Autowired
WebApplicationContext webApplicationContext; private XXXXServiceImpl xxxxServiceImpl; @Before
public void setUp(){ log.info("CustInvestMappersTest begin init");
xxxxServiceImpl= (XXXXServiceImpl ) webApplicationContext.getBean("xxxxServiceImpl");
} @Test
public void testLogin(){ }

}