0

嗨,我有一个控制器,我正在尝试测试,没有模拟。

@Controller
public class MyController
{
    @Autowired
    private Type1 service1;

    @Autowired
    private Type2 service2;

    ....
} 

测试类:

public class testController
{
    @Autowired
    private MyController controller;

    @Before
    public void setUp()
    {
        //setupStuff

    }

    @Test
    public void testControllerMethod()
    {
        //Test method
    }

}

通过测试进行调试时,我得到了控制器的值,但自动装配的 service1 和 2 的值为空。

xml 文件确实包含所有服务和控制器的基础包<context: component-scan>

如果删除它会给我创建 bean 的错误。即使我删除了其中一个服务基础包。

有什么测试需要添加到我的配置中吗?

类型1:

public interface Type1
{
    String method1();
    String method2();
}

自动装配的 Type1 实现类是:

@Service
public class Type1Class implements Type1
{
    @Autowired
    private Type3 service3;

    //Methods implementatoin of Type1
}



Type2 is similar to this.
4

0 回答 0