小编sea*_*ins的帖子

如何模拟儿童演员测试Akka系统?

当我在Akka中有一个父演员时,在初始化时直接创建一个子actor,当我想为父actor编写单元测试时,如何用TestProbe或mock替换子actor?

例如,使用以下设计的代码示例:

class TopActor extends Actor {
  val anotherActor = context.actorOf(AnotherActor.props, "anotherActor")

  override def receive: Receive = {
    case "call another actor" => anotherActor ! "hello"
  }
}

class AnotherActor extends Actor {

  override def recieve: Receive = {
    case "hello" => // do some stuff
  }

}
Run Code Online (Sandbox Code Playgroud)

如果我想为TopActor编写测试,要检查发送给AnotherActor的消息是"hello",我该如何替换AnotherActor的实现?看起来TopActor直接创建了这个子项,因此不容易访问.

unit-testing scala akka

14
推荐指数
1
解决办法
2393
查看次数

使用watir-webdriver自动化时如何处理tinyMCE?

我正在评估Watir-webdriver,以决定我是否可以切换到使用它进行我的浏览器测试(主要来自Watir),其中一个关键的事情就是能够与TinyMCE WYSIWYG编辑器进行交互,作为一些应用程序我使用TinyMCE.我设法让以下解决方案工作 -

@browser = Watir::Browser.new(:firefox)
@browser.goto("http://tinymce.moxiecode.com/tryit/full.php")
autoit = WIN32OLE.new('AutoITX3.Control')
autoit.WinActivate('TinyMCE - TinyMCE - Full featured example')
@browser.frame(:index, 0).body.click
autoit.Send("^a") # CTRL + a to select all
autoit.Send("{DEL}")
autoit.Send("Some new text")
Run Code Online (Sandbox Code Playgroud)

这种方法的缺点是,通过使用autoit,我仍然依赖于Windows,并且跨平台运行测试的能力是webdriver的吸引力之一.

我注意到一些具体的webdriver解决方案,如从下面的主题:

String tinyMCEFrame = "TextEntryFrameName" // Replace as necessary
this.getDriver().switchTo().frame(tinyMCEFrame);
String entryText = "Testing entry\r\n";
this.getDriver().findElement(By.id("tinymce")).sendKeys(entryText);
//Replace ID as necessary
this.getDriver().switchTo().window(this.getDriver().getWindowHandle());
try {
  Thread.sleep(3000);
} catch (InterruptedException e) {

  e.printStackTrace();
}

this.getDriver().findElement(By.partialLinkText("Done")).click(); 
Run Code Online (Sandbox Code Playgroud)

看起来它可能跨平台工作,但我不知道是否可以从Watir-webdriver中访问相同的功能.我的问题是,有没有办法使用watir-webdriver编写,删除和提交到TinyMCE,这不会强制依赖特定支持的浏览器或操作系统?

tinymce webdriver watir watir-webdriver

7
推荐指数
1
解决办法
2093
查看次数

从Scala中的字符串中获取字符但是将结果保存为字符串?

想象一下,我想从Scala中的字符串中获取字符,但是让toInt转换的行为与字符串上的字符相同,而不是字符上的字符串.

为了说明以下代码,行为如下:

"0".toInt // results in 0
"000".charAt(0).toInt // results in 48
Run Code Online (Sandbox Code Playgroud)

我想要第二行的版本也会导致0.我有一个如下的解决方案:

"000".charAt(0).toString.toInt // results in 0
Run Code Online (Sandbox Code Playgroud)

但我想知道是否有更直接或更好的方式?

scala

1
推荐指数
1
解决办法
49
查看次数

标签 统计

scala ×2

akka ×1

tinymce ×1

unit-testing ×1

watir ×1

watir-webdriver ×1

webdriver ×1