设为首页 加入收藏

TOP

Scala For Java的一些参考(六)
2017-10-10 12:13:02 】 浏览:2703
Tags:Scala For Java 一些 参考
la)

>~test-only scalatest.Test02  文件修改后自动运行单元测试【continuous mode】

The continuous mode works for the other SBT commands as well, such as  ~run or  ~test

作为Junit的单元测试方式运行

import org.junit.runner.RunWith

import org.scalatest.junit.JUnitRunner

import org.scalatest.FunSuite

@RunWith(classOf[JUnitRunner])

class MyTestSuite extends FunSuite ...

www.seleniumhq.org 功能测试

package scalatest

import org.scalatest._

import org.scalatest.selenium.WebBrowser

import org.openqa.selenium.htmlunit.HtmlUnitDriver

import org.openqa.selenium.firefox.FirefoxDriver

import org.openqa.selenium.WebDriver

class Test08 extends FlatSpec with Matchers with WebBrowser {

implicit val webDriver: WebDriver = new HtmlUnitDriver

go to "http://www.amazon.com"

click on "twotabsearchtextbox"

textField("twotabsearchtextbox").value = "Scala"

submit()

pageTitle should be ("Amazon.com: Scala")

pageSource should include("Scala Cookbook: Recipes")

}

www.scalamock.org

Web框架

alternatives to create web applications range from lightweight frameworks such as Unfiltered, Spray, or Scalatra to full-featured solutions such as the Lift or the Play Frameworks.

http://www.playframework.com/ http://www.playmodules.net

wpsA269.tmp

Web Service

Plugins.sbt

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" %"2.4.0")

addSbtPlugin("org.scalaxb" % "sbt-scalaxb" % "1.1.2")

resolvers += Resolver.sonatypeRepo("public")

build.sbt

import ScalaxbKeys._

name:="wssample"

scalaVersion:="2.10.2"

scalaxbSettings

ibraryDependencies += "net.databinder.dispatch" %% "dispatch-core" %"0.11.0"

libraryDependencies += "org.scalatest" %% "scalatest" % "2.0.M7" %"test"

sourceGenerators in Compile <+= scalaxb in Compile

packageName in scalaxb in Compile := "se.wssample"

XML/JSON

val books =

<Library>

<book title="Programming in Scala" quantity="15" price="30.00"

/>

<book title="Scala for Java Developers" quantity="10"

price="25.50" />

</Library>

import scala.xml._

val sameBooks = XML.loadString("""

<Library>

<book title="Programming in Scala" quantity="15"

price="30.00"/>

<book title="Scala for Java Developers" quantity="10"

price="25.50"/>

</Library>

""")

val total = (for {

book <- books \ "book"

price = ( book \ "@price").text.toDouble

quantity = ( book \ "@quantity").text.toInt

} yield price * quantity).sum

val books =

<Library>

{ List("Programming in Scala,15,30.00","Scala for Java

Developers,10,25.50") map { row => row split "," } map { b => <book

title={b(0)} quantity={b(1)} price={b(2)} /> }}

</Library>

import scala.util.parsing.json._

val result = JSON.parseFull("""

{

"Library": {

"book": [

{

"title": "Scala for Java Developers",

"quantity": 10

},

{

"title": "Programming Scala",

"quan

首页 上一页 3 4 5 6 下一页 尾页 6/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇函数式非凡的抽象能力 下一篇LINUX系统下Java和Scala的环境配置

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目