我定义了这些测试依赖项
/ Test Dependencies
lazy val wiremock = "com.github.tomakehurst" % "wiremock-jre8" % "2.25.1"
lazy val playTest = "com.typesafe.play" %% "play-test" % "2.8.1"
lazy val scalaTestPlusPlay = "org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0"
lazy val mockito = "org.mockito" %% "mockito-scala" % "1.10.2"
lazy val scalamock = "org.scalamock" %% "scalamock" % "4.4.0"
lazy val scalacheck_shapeless = "com.github.alexarchambault" %% "scalacheck-shapeless_1.14" % "1.2.3"
lazy val scalatest = "org.scalatest" %% "scalatest" % "3.1.1"
Run Code Online (Sandbox Code Playgroud)
但是我找不到这个特性来混合到我的测试规范类中:GeneratorDrivenPropertyChecks。我不确定我在这里缺少什么依赖项。在org.scalatest.prop
我没有看到这个特征。我只看到 TableDrivenPropertyChecks。
我在进行推送时收到此错误
git push
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 8 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 586 bytes | 195.00 KiB/s, done.
Total 7 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), completed with 6 local objects.
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: Commits must have valid signatures.
To https://github.com/xxx-xxx-xxx
! [remote rejected] master -> master (protected branch hook declined) …
Run Code Online (Sandbox Code Playgroud) 我添加sbt-toplecat
到我的 repo 并修复了我的代码的大部分错误,但有一个问题我不确定如何修复:
'nowarn' is not a valid choice for '-Wunused'
Run Code Online (Sandbox Code Playgroud)
我正在运行 Scala 2.13。如何解决此错误?
我有这样的类型:
sealed trait A extends Product with Serializable
object A{
case object B extends A
case object C extends A
implicit val format: OFormat[A] = derived.oformat()
}
Run Code Online (Sandbox Code Playgroud)
我正在使用play-json-derived-codecs来序列化上述类型。它工作正常,但是当我将 scala wartremover 库添加到我的项目时,它抛出了这个错误,我不知道如何修复:
[wartremover: Any] Inferred type containing Any: julienrf.json.derived.DerivedReads[A]
Run Code Online (Sandbox Code Playgroud)
我是否需要在某处添加一些类型注释来解决这个问题,还是我唯一的选择来抑制这个疣信号?
在Erlang/Elixir Actor模型中,如果一个actor发送一条消息,但由于任何原因(例如网络故障,VM崩溃),它无法到达目标actor,有没有办法重播该消息或者演员系统是否重视该消息已被发送?邮件是否可以保证发送?
我需要有关 URI API 的建议。
我正在制作这样的 URI
new URI("http", "", "localhost", 9000, "/action", "param=1","")
res0: java.net.URI = http://@localhost:9000/action?param=1#
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它将“@”放在 localhost 前面,并且我在 URI 末尾看到“#”。我怎样才能摆脱这些?他们为什么要来?
由于字符串的含义,我在比较字符串时遇到了很大的问题。例如,我有“ Yellow”之类的字符串和“ Blue”之类的字符串。在我的应用程序中,黄色小于蓝色。那么我如何建模呢?我试图像这样使用枚举
object Color extends Enumeration {
val yellow = Value(0)
val blue = Value(1)
}
Run Code Online (Sandbox Code Playgroud)
在我的职能中
def isBigger(color1 : String, color2 : String) = Boolean = {
???
}
Run Code Online (Sandbox Code Playgroud)
但是我不希望如何比较它们。请一些建议。
如果我有一个这样的案例类:
case class Foo(s : String, k : Int)
Run Code Online (Sandbox Code Playgroud)
如何为此指定一个空的构造函数?我需要这个的原因是因为我想将这个类的值传递给一个 Java API,它要求该类有一个空的构造函数。我是否为此指定默认值?我想我必须这样做,我别无选择。
对于我的测试,我创建了一个对象,其中包含我所有的案例类(即我的生成器)的任意实例:
object Generators
extends
FooGen
{
def sample[A](implicit gen: Gen[A]): A =
gen.sample.getOrElse(sys.error(s"Could not generate instance with $gen"))
implicit def arb[A](implicit g: Gen[A]): Arbitrary[A] = Arbitrary(g)
}
trait FooGen { this: GenUtils =>
implicit val fooGen: Gen[Foo] = gen[Foo]
}
Run Code Online (Sandbox Code Playgroud)
这当前位于我的 /test 文件夹下,因为我需要它为我的单元测试生成我的案例类的任意实例。但现在我想创建一些集成测试,这些测试将在我的 /it 文件夹下。将 /test 文件夹中的此生成器文件与 /it 文件夹中的测试共享的最佳方法是什么?
我的所有案例类都会有很多这样的生成器,所以我不想复制代码,这就是我问的原因。
我在理解上遇到了问题,如下所示:
def doSomething(): F[String] = {
for {
_ <- Future.traverse(items)(item => doSomeWork(item)) // Future[]
_ <- doSomeOtherWork(42) //F[]
} yield (())
}
Run Code Online (Sandbox Code Playgroud)
该函数doSomeWork
看起来像:
def doSomeWork(item: Item): Future[Unit] =
// some work done inside a Future
)
Run Code Online (Sandbox Code Playgroud)
功能doSomeOtherWork
工作如下:
def doSomeOtherWork(i : Int): F[Unit]
Run Code Online (Sandbox Code Playgroud)
因此,当我尝试编译时,遇到以下错误:
[error] found : F[Int]
[error] required: scala.concurrent.Future[?]
[error]
[error] ^
[error] type mismatch;
[error] found : scala.concurrent.Future[Nothing]
[error] required: F[Int]
Run Code Online (Sandbox Code Playgroud)
我不允许在这样的 for comp 中混合 F[] 和 Future 吗?
我有一个这种类型的值:
List[Either[Error, Files]]
Run Code Online (Sandbox Code Playgroud)
我有一个函数可以检查是否存在这样的错误:
private def process(result: List[Either[Error, Files]]): Either[Error, List[Files]] = {
if(result.exists(p => p.isLeft)){
Left(Error("some downloads failed"))
}else{
Right(
Right(
result.collect {
case Right(value) => value
}
)
}
}
Run Code Online (Sandbox Code Playgroud)
如果结果没有错误,这是返回文件列表的最佳方法吗?