Skip to content

Instantly share code, notes, and snippets.

@fpopic
Last active January 22, 2018 15:58
Show Gist options
  • Select an option

  • Save fpopic/97202d96590f1a5d13bf76f06da82f12 to your computer and use it in GitHub Desktop.

Select an option

Save fpopic/97202d96590f1a5d13bf76f06da82f12 to your computer and use it in GitHub Desktop.
import org.apache.beam.sdk.transforms.DoFn.ProcessElement
import org.apache.beam.sdk.transforms.{DoFn, DoFnTester}
import org.scalatest.{FlatSpec, Matchers}
class MyDoFn extends DoFn[Integer, Integer] {
@ProcessElement
def processElement(c: ProcessContext): Unit = {
c.output(c.element * 2)
}
}
class MinimalDoFnSpec extends FlatSpec with Matchers {
val tester: DoFnTester[Integer, Integer] = DoFnTester.of(new MyDoFn())
"MyDoFn" should " multiply all elements by two" in {
val actualOutput = tester.processBundle(1, 2, 3)
val expectedOutput = Seq(2, 4, 6)
actualOutput should contain only (expectedOutput: _*)
}
}
@fpopic

fpopic commented Jan 22, 2018

Copy link
Copy Markdown
Author

For Testing DoFn with ScalaTest:

  "org.scalatest" %% "scalatest" % scalatestVersion % Test,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment