久久久久久久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 一起使用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試使用 TDD.我正在嘗試使用 Mockito 結(jié)合 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 失敗,我在設(shè)置中初始化 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 并將其配置到項目的構(gòu)建路徑中解決了這個問題,但隨后我面臨

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.

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

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.

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

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 的參數(shù).它將列出所有加載的類,如果我沒記錯的話,它們是從哪里加載的.請參閱 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.

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

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

相關(guān)文檔推薦

How to mock super reference (on super class)?(如何模擬超級參考(在超級類上)?)
Java mock database connection(Java 模擬數(shù)據(jù)庫連接)
Mockito ClassCastException - A mock cannot be cast(Mockito ClassCastException - 無法投射模擬)
Set value to mocked object but get null(將值設(shè)置為模擬對象但獲取 null)
How to mock DriverManager.getConnection(...)?(如何模擬 DriverManager.getConnection(...)?)
Mockito; verify method was called with list, ignore order of elements in list(模擬;使用列表調(diào)用驗證方法,忽略列表中元素的順序)
主站蜘蛛池模板: 国产精品片aa在线观看 | 欧美日韩黄| 黄网免费看 | 久久久久黄色 | 午夜精品一区二区三区在线视频 | 欧美色欧美亚洲另类七区 | 天天草草草 | 国产福利精品一区 | 久久久久久久久久久久91 | 9久9久9久女女女九九九一九 | 在线观看亚洲精品视频 | 免费h视频 | 99这里只有精品 | 亚洲网站在线观看 | 成人深夜福利在线观看 | 中文字幕视频一区二区 | 一区二区久久 | av看片| 伊人狠狠干 | 国产影音先锋 | a在线免费观看 | 黄色男女网站 | 成人a视频 | 综合精品在线 | 国产福利免费视频 | 99tv| 黑人精品欧美一区二区蜜桃 | 午夜久久久 | 一区二区三区电影在线观看 | 91成人 | 国产精品美女久久久 | 欧美aⅴ片| 国产一在线观看 | 91手机精品视频 | 国外成人在线视频网站 | 国产高潮好爽受不了了夜夜做 | 亚欧洲精品在线视频免费观看 | 人人九九| 欧美精品在线播放 | 粉嫩av在线| 中文字幕91av |