Spring - JUnit Integration Test

1, the leader packet: test.jar

2, create notes using @RunWith spring container - @RunWith (SpringJUnit4ClassRunner.class)

3, using @ContextConfiguration read the spring configuration file - @ContextConfiguration ( "classpath: applicationContext.xml")    

4, bean objects acquired using the assembled @Resource

package com.sikiedu.test;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.sikiedu.service.UserService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration ( "CLASSPATH: the applicationContext.xml" )
 public  class AopTest {
     // the object named userService injected into the UserService 
    @Resource (name = "userService" )
     Private UserService US;

    @Test
    public  void test2 () {

        us.delete();

    }
}

Guess you like

Origin www.cnblogs.com/Dm920/p/12076593.html