Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: Defining test cases based on folder

I have to test a program which takes one input file. I have put all the input files inside a folder and now I want to use SBT and ScalaTest to have following features:

  • TestAll : Invoke the program with one input file at a time for all files
  • Test one: Invoke the program with one input file provided as argument to test command from sbt console

For the time being foldername is a fixed path, so list of all files can be obtained by:

val dir = new File("tests\\");
val files = dir.listFiles.filter(
  f => """.*\.extension$""".r.findFirstIn(f.getName).isDefined);

Can any one give me a brief idea as to which scalatest class is best suited for this purpose?

like image 879
thequark Avatar asked Nov 05 '22 10:11

thequark


1 Answers

I think you should consider refactoring the program so that you have a method which takes an InputStream rather than a file. That way you can test the method without worrying about files. Of course it depends on the structure and size of the files.

If you don't want to do that you can implement your own SBT Task with a parameter (the filename).

http://code.google.com/p/simple-build-tool/wiki/CustomActions

http://code.google.com/p/simple-build-tool/wiki/MethodTasks

like image 98
michael.kebe Avatar answered Nov 15 '22 06:11

michael.kebe