Junit白盒测试

Junit白盒测试_第1张图片

步骤一:导入jar包(junit-4.10.jar,org.springframework.test-3.0.0.M3.jar)

步骤二:BaseTestCase.java


package com.app.junit;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Junit注入
 * @author liyisong
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { "classpath:applicationContext.xml" })
public class BaseTestCase {
}

步骤三:

import static org.junit.Assert.assertEquals;

import javax.annotation.Resource;

import org.junit.Test;

import com.app.service.spi.ISLoginService;
/**
 * 测试 LoginService
 * @author liyisong 
 * 
 * extends BaseTestCase , 注入service
 */
public class LoginServiceTest extends BaseTestCase{
	@Resource(name = "loginService")
	private ISLoginService loginService;

	@Test
	public void testGetSuperManagerRoleType() {
		String superManagerRoleID = "10000000";
		String roletype = loginService.getSuperManagerRoleType(superManagerRoleID);
		assertEquals("SYS_ROLE",roletype);
	}

}



你可能感兴趣的:(Java,Junit,Junit白盒测试)