spring + junit 测试
需要一个工具类
package com.meizu.fastdfsweb;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring-context.xml")
public abstract class BaseSpringContextUnitTest {
}
测试例子:
package com.meizu.fastdfsweb.entity;
import junitx.framework.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.meizu.fastdfsweb.BaseSpringContextUnitTest;
public class ClusterConfigTest extends BaseSpringContextUnitTest {
@Autowired
ClusterConfig clusterConfig;
@Test
public void testGetClusterNum() {
System.out.println(clusterConfig);
Assert.assertEquals(2, clusterConfig.getClusterNum());
}
}