Scala 为什么这个简单的鹅毛笔引用无法编译?
我正在试用scala和quill(getquill.io)。下面这个最小的示例无法编译。为什么呢?它只定义了一个类。我怀疑我需要以某种方式标记该类,以便quill能够解析它,但我不知道如何进行。我被鹅毛笔吸引了,因为我不需要加分案例类,它们应该只起作用,对吗Scala 为什么这个简单的鹅毛笔引用无法编译?,scala,quill,Scala,Quill,我正在试用scala和quill(getquill.io)。下面这个最小的示例无法编译。为什么呢?它只定义了一个类。我怀疑我需要以某种方式标记该类,以便quill能够解析它,但我不知道如何进行。我被鹅毛笔吸引了,因为我不需要加分案例类,它们应该只起作用,对吗 package dbquerytest import io.getquill._ /*in a real life you would rather pass execution context as a method or cons
package dbquerytest
import io.getquill._
/*in a real life you would rather pass execution context as
a method or constructor argument, but we're just playing*/
import scala.concurrent.ExecutionContext.Implicits.global
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
case class Intake( id:Int, path:String, stage:Int) // , timestamp: Instant
// running/using junit test:https://alvinalexander.com/scala/how-to-use-junit-testing-with-scala
class MysqlLocalDbTest {
@Test
def testIntake={
val ctx = new MysqlAsyncContext(SnakeCase, "testdb")
import ctx._
val intakes = quote { query[Intake].map(_.id )}
ctx.run(intakes).map(_.headOption)
assertEquals(0,0)
}
}
编译在io.getquill.quote.Parsing处失败。首先,我可以看到您在代码段中使用的是JUnit5,但似乎存在一些问题。将JUnit5与Scala和sbt一起使用:。替代方法包括使用JUnit4或Scala特定的测试库,如ScalaTest或specs2(ScalaCheck也值得一提,尽管我通常只将其与ScalaTest或specs2结合使用) 其次,我不知道您正在使用哪个构建工具,也不知道您是否拥有所有相关的依赖项,这可能是导致编译错误的原因。如果您使用的是sbt(),我认为它是使用Scala开发时最常见的构建工具,那么您的示例中可能会用到的一个例子是(使用JUnit4): build.sbt:
导入依赖项_
此构建/规模规避:=“2.12.8”
此生成/版本:=“0.1.0-快照”
此构建/组织:=“com.example”
ThisBuild/organizationName:=“示例”
lazy val root=(文件中的项目(“.”)
.设置(
名称:=“绗缝”,
libraryDependencies++=Seq(
“mysql”%“mysql连接器java”%“8.0.15”,
“io.getquill”%%“quill jdbc”%%“3.1.0”,
“io.getquill”%%“quill异步mysql”%%“3.1.0”,
//少年4。
“com.novocode”%”junit接口“%”0.11“%Test”
)
)
要从头开始生成一个使用sbt进行测试的快速项目,请在某处创建一个新文件夹,从命令行进入该文件夹,然后运行sbt new sbt/scala seed.g8
。然后进入文件夹,运行sbt
。之后,运行test
我已将您的示例更改为使用JUnit 4,它似乎可以编译并运行:
包dbquerytest
导入io.getquill_
/*在现实生活中,您更愿意将执行上下文作为
方法或构造函数参数,但我们只是在玩*/
导入scala.concurrent.ExecutionContext.Implicits.global
导入org.junit.Test
导入junit.framework.TestCase
导入org.junit.Assert_
案例类接收(id:Int,path:String,stage:Int)
//运行/使用junit测试:https://alvinalexander.com/scala/how-to-use-junit-testing-with-scala
类MysqlLocalDbTest{
@试验
def testIntake={
val ctx=新的MysqlAsyncContext(蛇壳,“testdb”)
进口ctx_
val intakes=quote{query[intakes].map(u.id)}
ctx.run(入口).map(u.headOption)
资产质量(0,0)
}
}
如果您想尝试其他一些示例,还有一个,如中所链接。非常感谢,这终于让我摆脱困境了!:)