Spring:我希望为 Web 应用程序创建一个 junit 测试 - 需要 WebApplicationContext [英] Spring: I wish to create a junit test for a web application - WebApplicationContext needed

查看:27
本文介绍了Spring:我希望为 Web 应用程序创建一个 junit 测试 - 需要 WebApplicationContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 junit 测试,以便(令人惊讶地)将我的应用程序的一部分作为一个独立的部分进行测试.

I am writing a junit test in order to (surprisingly) test a part of my app as a standalone.

事情是我在单元测试中调用的构造函数中执行以下行:

Thing is I execute the following line in a constructor being invoked in the unit test:

WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();

在运行简单的单元测试时,我将如何设置 Web 上下文?

How would I go about to set up a web context when running a simple unit test?

谢谢

推荐答案

  • 在单元测试中,使用模拟进行测试.
  • 在集成测试中,您可能实际上想要启动一个嵌入式 servlet 容器.这是一种方法.
  • 这篇关于Spring:我希望为 Web 应用程序创建一个 junit 测试 - 需要 WebApplicationContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆