久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRe

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted() while using Mockito with Junit(java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted() 將 Mockito 與 Junit 一起使用) - IT屋
本文介紹了java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted() 將 Mockito 與 Junit 一起使用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試使用 TDD.我正在嘗試使用 Mockito 結合 MockMvc 和 Junit 為控制器編寫單元測試用例.

I am trying to get my feet wet with TDD. I am trying to write unit test cases for controllers using Mockito in conjunction with MockMvc and Junit.

但是我遇到了運行時錯誤,因此我的測試失敗了.起初,由于找不到 javax.servlet.SessionCookieConfig 失敗,我在設置中初始化 MockMvc 實例時遇到了問題.

But I am getting a runtime error thereby failing my test. At first I was facing problem in initializing the MockMvc instance in the setup due to failure in finding the javax.servlet.SessionCookieConfig.

我通過下載 javax.servlet api 并將其配置到項目的構建路徑中解決了這個問題,但隨后我面臨

This I resolved by downloading the javax.servlet api and configuring it into the build path of the project but then I am facing the

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()

在 MockMvc 實例上使用 perform() 時.

while using perform() on the MockMvc instance.

誰能告訴我如何處理這種依賴關系,因為我認為這是由于服務器 servlet-api 和 javax.servlet api 不兼容而發生的.

Can anyone tell me what to do with this kind of dependencies as I think it is occurring due to the incompatible server servlet-api and javax.servlet api.

我正在發布我用于單元測試的代碼,但我認為這不會有任何幫助,但以防萬一:

EDIT : I am posting the code I am using using for unit testing but I don't think it would be any help but just in case :

@RunWith(MockitoJUnitRunner.class)
public class MyControllerTest {

    @InjectMocks
    private MyController myController = new MyController();

    @Mock
    private MyService myService = new MyServiceImpl();

    private MockMvc mockMvc;

    @Before
    public void setUp(){
        this.mockMvc = MockMvcBuilders.standaloneSetup(myController).build();
    }

    @Test
    public void testList() throws Exception{
        A a = new A();
        a = createMockClassA();

        Mockito.when(myService.getServiceForA(Mockito.anyMapOf(String.class, String.class))).thenReturn(a);

        MvcResult result = this.mockMvc.perform(get("/somePath/")).param("someExpectedParam","value").andReturn(); 

        System.out.println(result.getResponse().getContentAsString());

    }



    private static A createMockClassA(){
        A a = new A();
        a.setId(i);
        a.setTitle("mock-" + i);
        return a;
    }
}

推薦答案

這聽起來很像您在類路徑中的 servlet API 版本錯誤.

This sounds very much like you have the wrong version of the servlet API in the class path.

檢查何時將 isAsyncStarted 添加到 API,并確保您在類路徑中引用的版本至少是該版本或更高版本.

Check when isAsyncStarted was added to the API and make sure the one you reference in your classpath is at least that version or higher.

為了找到錯誤"類版本來自的位置,您可以使用

In order to find the location where the 'wrong' class version is comming from you can use the

-verbose:class

java 的參數.它將列出所有加載的類,如果我沒記錯的話,它們是從哪里加載的.請參閱 http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html了解詳情.

Argument for java. It will list all the classes loaded and if I remember correctly whery they get loaded from. See http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html for details.

這篇關于java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted() 將 Mockito 與 Junit 一起使用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to mock super reference (on super class)?(如何模擬超級參考(在超級類上)?)
Java mock database connection(Java 模擬數據庫連接)
Mockito ClassCastException - A mock cannot be cast(Mockito ClassCastException - 無法投射模擬)
Set value to mocked object but get null(將值設置為模擬對象但獲取 null)
How to mock DriverManager.getConnection(...)?(如何模擬 DriverManager.getConnection(...)?)
Mockito; verify method was called with list, ignore order of elements in list(模擬;使用列表調用驗證方法,忽略列表中元素的順序)
主站蜘蛛池模板: 欧美日韩国产综合在线 | 亚洲成人免费 | 久干网 | 日本亚洲一区 | 性国产xxxx乳高跟 | 欧美日韩综合一区 | 成人免费视频观看 | 欧美性受| 日韩精品成人免费观看视频 | 日本高清中文字幕 | 亚洲精品视频一区 | 久久午夜视频 | 久久久久国产精品 | 成人一区在线观看 | 91久久久久久久久久久久久 | 久久不射网 | 国产精品久久久久久久岛一牛影视 | a精品视频| 99精品99| 成人黄视频在线观看 | 欧美成人a∨高清免费观看 色999日韩 | 日本一区二区不卡 | 中文字幕成人免费视频 | 久久精品中文 | 成人免费在线 | 一级片av | 国产精品欧美一区二区三区不卡 | 国产 日韩 欧美 中文 在线播放 | 欧美成人a∨高清免费观看 欧美日韩中 | 高清久久久 | 日韩福利 | 2020天天操| 国产精品一区二区在线播放 | 99在线播放 | 欧美精品欧美精品系列 | 网色| 91一区二区三区 | 中文字幕一区二区三区四区五区 | 911网站大全在线观看 | 1204国产成人精品视频 | 亚洲高清av |