Returning to Scala after being away a year


#1

I’d like to write some small scale programs to get myself back into the language after being away a
year or more. I’m having trouble understanding again the development and testing model.

What I’d like to do is write an application which I can run from the UNIX command line, which
reads lines from stdin, does some processing, and prints to stdout. However, I’d like to be
able to test the program without having to go to the unix command line. I.e., I’d like to write
tests for intermediate functions by pushing a button within IntelliJ.

Can someone suggest a pattern for doing this, or a template, or a resource I can read which explains
how it is supposed to work?

I’ve created the project in IntelliJ, and I have a src/main/scala directory (where the source file[s] should live) directory and a src/test/scala directory (where the testing file[s] should live).

23

Certainly I’d love to use some property based testing, but as I understand, there is a huge amount of overhead boilerplate work necessary to get the first property based test to work. Hopefully I’m wrong.


#2

Aokm


#3

Aokm = Army Operational Knowledge Management ?


#4

Might I suggest an alternative that does use the command line but is fully automated (I am assuming you will be using a testing framework like Scalatest [0] or Junit): use Sbt [1] or Mill [2] and execute the tests (or specific test or main function) continuously. With Sbt that would be the command “~ test” (note the tilde). With Mill you would use the “–watch” [3].

In the case of Sbt, you can run that within the IDE Sbt console. You can then click on the error messages to jump to the relevant code. Unfortunately no support for Mill, use the console.

I would however suggest Mill - it is easy to install and set-up.

  1. http://www.scalatest.org/
  2. https://www.scala-sbt.org/
  3. http://www.lihaoyi.com/mill/
  4. http://www.lihaoyi.com/mill/#watch-and-re-evaluate

HTHs