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?
해결책
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