Skip to content

Commit

Permalink
Add roboelectric test
Browse files Browse the repository at this point in the history
  • Loading branch information
pocorall committed Jan 8, 2016
1 parent 6ac62b1 commit 166deda
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/main/scala/scaloid/example/HelloScaloid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/test/scala/scaloid/example/HelloScaloidTest.scala
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit 166deda

Please sign in to comment.