You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Play Framework的Scala项目Specs2 Mockito抛出NoSuchMethodError

Play Framework Scala项目Specs2测试抛出NoSuchMethodError异常

运行测试时出现如下异常:

Exception in thread "specs2-7" java.lang.NoSuchMethodError: 'scala.collection.immutable.Stream org.specs2.data.Trees$Treex.flattenLeft()'
  | => cat org.specs2.reporter.JUnitDescriptions.fragmentDescriptions(JUnitDescriptions.scala:69)
    at org.specs2.reporter.JUnitDescriptions.fragmentDescriptions$(JUnitDescriptions.scala:68)
    at org.specs2.reporter.JUnitDescriptions$.fragmentDescriptions(JUnitDescriptions.scala:115)
    at org.specs2.reporter.JUnitXmlPrinter.descriptions(JUnitXmlPrinter.scala:52)
    at org.specs2.reporter.JUnitXmlPrinter.descriptions$(JUnitXmlPrinter.scala:51)
    at org.specs2.reporter.JUnitXmlPrinter$.descriptions(JUnitXmlPrinter.scala:117)
    at org.specs2.reporter.JUnitXmlPrinter.$anonfun$saveResults$1(JUnitXmlPrinter.scala:35)
    at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:163)
    at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:141)
    at org.specs2.control.origami.Fold$$anon$2.end(Fold.scala:44)

环境信息

  • Play Framework版本:2.8.19
  • Scala版本:2.12.17
  • Java版本:17
  • specs2-mock版本:4.13.3
  • specs2-core版本:4.13.3
  • scalac配置:scalacOptions:=Seq("-release", "17")

已尝试将specs2版本从4.13.3升级到4.17.0、4.20.0,但问题未解决。同时已按照Play Framework官方要求完成Java 17下的运行配置。

测试用例示例代码:

import org.specs2.mock.Mockito
import org.specs2.mutable.Specification

class DemoTest extends Specification with Mockito {

  isolated

  "DemoTest.calculate" should {

    """ return 5""" in {

      val demo = new Demo()

      demo.run() shouldEqual 5
    }

  }

}

请问该问题的可能原因是什么?原本以为升级Specs2版本能解决问题,但并未奏效。

内容的提问来源于stack exchange,提问作者Shashi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 14:27:25