On Tue, 4 Dec 2012 08:04:41 -0800 (PST)
Ross Lawley <
ross....@gmail.com> wrote:
> Hi,
>
> I have an inherited project which imports data everytime sbt is run,
> however, I want to run a task only if running test / test-only. Whats the
> best way to achieve that?
>
> I've tried adding the following to my build.scala, which I thought would
> run in the Test scope:
>
> lazy val loadTestData = TaskKey[Unit]("load-test-data")
> fullRunTask(loadTestData, Test, "TestDataImport")
>
> But TestDataImport never called as I'd expected - any ideas how best to run
> the task test data before running tests?
That just defines a task test:load-test-data. It doesn't make it a dependency of any other task.
> Or is this out of the scope of sbt and should be put in the some Specs2
> code?
If Specs2 supports this, yes, that would be the right place. Otherwise, there are two options that I can think of.
1.
http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing.html#setup-and-cleanup
2. Since you already have defined the task that does the side effect you want, you could say
loadTestData <<= loadTestData runBefore test
That would go after the fullRunTask call. It doesn't work for testOnly, which is an input task. You'd need the workaround of
loadTestData <<= loadTestData runBefore testGrouping
That would work for both test and testOnly and I don't think it would run in unexpected situations.
-Mark
>
> Ross
>
> --
> You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
> To view this discussion on the web visit
https://groups.google.com/d/msg/simple-build-tool/-/jsAzYScWvQYJ.
> To post to this group, send email to
simple-b...@googlegroups.com.
> To unsubscribe from this group, send email to
simple-build-t...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/simple-build-tool?hl=en.
>