From 166deda0dd7955aeb5080c0e73251518e25feb61 Mon Sep 17 00:00:00 2001 From: Sung-Ho Lee Date: Fri, 8 Jan 2016 10:07:19 +0900 Subject: [PATCH] Add roboelectric test --- README.markdown | 7 +++++++ build.sbt | 12 ++++++++++++ .../scala/scaloid/example/HelloScaloid.scala | 3 ++- .../scaloid/example/HelloScaloidTest.scala | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/test/scala/scaloid/example/HelloScaloidTest.scala diff --git a/README.markdown b/README.markdown index f385a1b..53d933b 100644 --- a/README.markdown +++ b/README.markdown @@ -27,6 +27,13 @@ Run For more command, refer to [android-sdk-plugin for sbt](https://github.com/pfn/android-sdk-plugin). +Test +----- +A simple [Robolectric](http://robolectric.org/) test is implemented. You can run it with: + + $ sbt test + + Tips for faster development iteration ------------------------------------- In sbt, `~` is a prefix that repeatedly runs the command when the source code is modified. diff --git a/build.sbt b/build.sbt index 506a2e0..ce82107 100644 --- a/build.sbt +++ b/build.sbt @@ -19,3 +19,15 @@ libraryDependencies += "org.scaloid" %% "scaloid" % "4.1" run <<= run in Android install <<= install in Android + +// Tests ////////////////////////////// + +libraryDependencies ++= Seq( + "org.apache.maven" % "maven-ant-tasks" % "2.1.3" % "test", + "org.robolectric" % "robolectric" % "3.0" % "test", + "junit" % "junit" % "4.12" % "test", + "com.novocode" % "junit-interface" % "0.11" % "test" +) + +// without this, @Config throws an exception, +unmanagedClasspath in Test ++= (bootClasspath in Android).value \ No newline at end of file diff --git a/src/main/scala/scaloid/example/HelloScaloid.scala b/src/main/scala/scaloid/example/HelloScaloid.scala index 35e2990..af646b8 100644 --- a/src/main/scala/scaloid/example/HelloScaloid.scala +++ b/src/main/scala/scaloid/example/HelloScaloid.scala @@ -5,6 +5,7 @@ import android.graphics.Color class HelloScaloid extends SActivity { lazy val meToo = new STextView("Me too") + lazy val redBtn = new SButton(R.string.red) onCreate { contentView = new SVerticalLayout { @@ -18,7 +19,7 @@ class HelloScaloid extends SActivity { STextView("I am 15 dip tall") textSize 15.dip // overriding new SLinearLayout { STextView("Button: ") - SButton(R.string.red) + redBtn.here }.wrap.here SEditText("Yellow input field fills the space").fill } padding 20.dip diff --git a/src/test/scala/scaloid/example/HelloScaloidTest.scala b/src/test/scala/scaloid/example/HelloScaloidTest.scala new file mode 100644 index 0000000..1934585 --- /dev/null +++ b/src/test/scala/scaloid/example/HelloScaloidTest.scala @@ -0,0 +1,18 @@ +package scaloid.example + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.annotation.Config +import org.robolectric.{Robolectric, RobolectricTestRunner} + +@RunWith(classOf[RobolectricTestRunner]) +@Config(manifest = "src/main/AndroidManifest.xml") +class HelloScaloidTest { + @Test def testButtonPressed(): Unit = { + val activity = Robolectric.setupActivity(classOf[HelloScaloid]) + assertTrue(activity.meToo.text == "Me too") + activity.redBtn.performClick() + assertTrue(activity.meToo.text == "PRESSED") + } +} \ No newline at end of file