1, 导入 spring-test-3.2.0.RELEASE.jar   

2.添加依赖包  项目右键单击BuildPath>AddLibrary>JUnit    选JUnit4  完成.

3.创建测试类

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 com.level.service.TestService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:beans.xml")//加载spring容器配置文件
public class TestJUnit {
    @Autowired
    TestService testService;
    @Test
    public void test1(){
        testService.save();
    }

}

 

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2021-11-12
  • 2021-08-31
  • 2022-12-23
  • 2021-10-01
  • 2021-12-18
猜你喜欢
  • 2021-11-13
  • 2021-07-08
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
相关资源
相似解决方案