1. 程式人生 > >Spring4.3.8使用單元測試報錯

Spring4.3.8使用單元測試報錯

1.新增junit-4.8.2.jar,測試出現問題報錯java.lang.noclassdeffounderror:org/apache/commons/logging/LogFactory,查詢發現是缺少支援jar,新增支援commons-logging-1.1.3.jar

2.繼續報錯需要junit-4.12以上

3.新增支援junit-4.12.jar

4.執行繼續報錯,java.lang.noclassdeffounderror:org/hamcrest/SelfDescribing

終極解決,查詢發現:

junit.jar: Includes the Hamcrest classes. The simple all-in-one solution to get started quickly.Starting with version 4.11, Hamcrest is no longer included in this jar.

junit-dep.jar: Only includes the JUnit classes but not Hamcrest. Lets you use a different Hamcrest version.

說明4.11中沒有hamcrest包了
最好的解決方法是:

使用是匯入包的方案:junit.jar + hamcrest-core.jar + hamcrest-library.jar

分別下載所用jar,hamcrest-core-1.3.jar和hamcrest-library-1.3.jar

執行測試,問題解決。

相關推薦

Spring4.3.8使用單元測試

1.新增junit-4.8.2.jar,測試出現問題報錯java.lang.noclassdeffounderror:org/apache/commons/logging/LogFactory,查詢發現是缺少支援jar,新增支援commons-logging-1

【JUnit 】 method initializationerror not found:JUnit4單元測試問題

inf 修改 分享圖片 cli ips onerror image initial bubuko 1、不僅方法要public,類也要是public權限 2、修改Java文件字符集 沒有完成,決定修改eclipse的默認字符集為gdk,需要使用時再修改為ut

Android studio執行單元測試: Class Not Found: Empty Test Suite

使用Espresso時報錯 Class not found: “com.test.LoginUnitTest”Empty test suite. 原因:沒有將該測試類新增到InstrumentedTest中 解決: 1.開啟配置,選擇Edit Configurations

spring單元測試:萬用字元的匹配很全面, 但無法找到元素 'tx:advice' 的宣告。

報錯:Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 54 in XML document from class path resource [app

IDEA執行單元測試 @{argLine}

sentinel是今年阿里開源的高可用防護的流量管理框架。 git地址:https://github.com/alibaba/Sentinel wiki:https://github.com/alibaba/Sentinel/wiki FAQ:https://github.com/alibaba/Sen

method initializationerror not found:JUnit4單元測試問題

       今天使用JUnit 4進行單元測試時,測試程式一直執行不起來,報method initializationerror not found錯誤,如下:          網上說版本不

Spring Boot中使用Test單元測試javax.websocket.server.ServerContainer not available

測試mybatis註解增刪改查的時候,單元測試的時候,webSocket報錯。只需要在測試類增加註解 @SpringBootTest(classes = {Application.class},webEnvironment =SpringBootTest.WebEnvironment.RAN

spring接入swagger後單元測試

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMa

Spring配置事務,Junit單元測試"Failed to load ApplicationContext"

問題: Junit單元測試程式碼如下: package cn.muke.spring.demo2; import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; imp

單元測試:unable to find a @SpringBootConfiguration

問題描述 今天做單元測試報錯:unable to find a @SpringBootConfiguration   問題原因 有幾種可能性,逐個排除下對症下藥: 1.程式入口類忘了新增:SpringBootApplication註解 2.程式入口類的包名和測試

javaJunit單元測試:Test is not an annotation type

今天寫一個小demo是用到單元測試,但是當我在方法上加上@Test的時候報錯:Test is not an annotation type 最後發現是因為我的同一個包裡面有一個叫做Test的類,衝突了。把Test類改個名字或者刪掉,問題解決。

Class cannot be resolved to a type spring4.32的junit測試解決

直接上bug Class<SpringJUnit4ClassRunner> cannot be resolved to a type 看程式碼 @RunWith(SpringJUn

匯入junit4.11.jar包進行單元測試的解決方法

昨晚下了一個最新的junit包junit4.11.jar進行單元測試,結果不知道為什麼老是報java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing錯誤,找了半天結果去官網才發現: 所以還需要將hamcres

Django 中的 csrf_token 與單元測試處理

在Harry J.W. Percival 所著的<Python Web開發:測試驅動方法>中的第五章,在單元測試部分存在一個bug。 即,在高版本的Django(>1.7)中,在渲染模板時,Django 會把這個模板標籤替換成一個<input ty

突然發現junit單元測試竟然與類中的有參構造有關

java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test1], {ExactMatcher:fDisplayName=test1(com.test.User)], {LeadingIdentifierMatche

poi匯出excel 3.14版本合併單元

poi匯出excel合併單元格的時候 , 執行sheet.addMergedRegion(new CellRangeAddress(rowNumber, (short) rowNumber, 0, (

安裝zabbix-3.2.6編譯no acceptable C compiler

zabbix linux執行安裝zabbix在編譯的時候./configure --prefix=/usr/local/zabbix/ --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libc

Spring Web 項目Junit測試問題

繼承 text config web項目 cap 正是 obj ssr and 測試對象是Web項目的Service類,參照網上查到的資料,按如下方式執行時報錯, //使用junit4進行單元測試 @RunWith(SpringJUnit4ClassRunner.c

Python學習筆記__8.3單元測試

編程語言 Python # 這是學習廖雪峰老師python教程的學習筆記1、概覽單元測試是用來對一個模塊、一個函數或者一個類來進行正確性檢驗的測試工作。比如對函數abs(),我們可以編寫出以下幾個測試用例:輸入正數,比如1、1.2、0.99,期待返回值與輸入相同;輸入負數,比如-1、-1.2、-0.9

Android studio 升級到3.0後各種解決方法

   最近把AS升級到3.2.1後老工程出現了一系列問題 總的來說, 不要隨便用最新的東西, SDK也好,AS也好,對老工程都不友好, 要等其他人躺坑躺的差不多再搞 我是先把gradle直接升級到了5.0, AS升級到了3.2.1 , SDK升到了28, 然後就