久久久久久久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(模擬;使用列表調用驗證方法,忽略列表中元素的順序)
主站蜘蛛池模板: 久久久国产精品网站 | www.欧美视频| 欧美成人精品欧美一级 | 国产清纯白嫩初高生视频在线观看 | 欧美中文一区 | 一级毛片大全免费播放 | 国产精品国产亚洲精品看不卡15 | 午夜精品一区二区三区在线观看 | 成年人黄色一级片 | 两性午夜视频 | 欧美日高清视频 | 亚洲欧美日韩精品久久亚洲区 | 在线看一区二区 | 亚洲成人福利在线观看 | 国内精品久久精品 | 九九热精品视频 | 国产精品成人在线播放 | 欧洲av一区| 欧美一区二区三区免费在线观看 | 亚洲综合婷婷 | 亚洲精品一区二区久 | 久久精品久久久久久 | 男女羞羞视频大全 | 九九久视频 | 亚洲二区在线 | 国产激情免费视频 | 亚洲一区欧美 | 一区二区精品在线 | 国产农村妇女毛片精品久久麻豆 | 成人性视频在线播放 | 午夜精品一区二区三区在线观看 | 一级做a爰片性色毛片视频停止 | 国产精品视频网 | www,黄色,com | 国产成人短视频在线观看 | 亚洲网站在线观看 | 国产一区二区三区四区 | 一区二区福利视频 | 欧美视频一区二区三区 | 亚洲乱码国产乱码精品精98午夜 | 欧美福利 |