executing the Suite.run method to get test Status - is it possible? Args class properties cannot be constructed as instances are private :(

34 views
Skip to first unread message

Shannon

unread,
Jul 10, 2015, 9:14:15 AM7/10/15
to scalate...@googlegroups.com
I was wondering if anyone has been able to successfully do this, seeing as the Args class required for the run method has properties which are all private implementations, thus not accessible.

I am trying to get back the Status of a test (isSuccessful, etc), and this seems like the only option as the execute method returns Unit

So I am now wondering why is run public? And is there am alternate way of running a test and getting the status back

def run(testName : scala.Option[scala.Predef.String], args : org.scalatest.Args) : org.scalatest.Status 

Bill Venners

unread,
Jul 10, 2015, 9:42:37 AM7/10/15
to scalate...@googlegroups.com
Hi Shannon,

You are indeed supposed to be able to call run, including constructing
Args. Can you let me know what exactly you're trying to do where
you're hitting something private that you want?

Also, possibly taking a step back, let me know what you are trying to
accomplish in the first place that you need Status for. It is intended
to be used, but it is relatively rare that people do so, so it might
help if I know the context.

Thanks.

Bill
> --
> You received this message because you are subscribed to the Google
> Groups "scalatest-users" group.
> To post to this group, send email to scalate...@googlegroups.com
> To unsubscribe from this group, send email to
> scalatest-use...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/scalatest-users?hl=en
> ScalaTest itself, and documentation, is available here:
> http://www.artima.com/scalatest
> ---
> You received this message because you are subscribed to the Google Groups
> "scalatest-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scalatest-use...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Bill Venners
Artima, Inc.
http://www.artima.com

Sujan Kapadia

unread,
Oct 26, 2015, 11:33:08 AM10/26/15
to scalatest-users
All,

I also find myself in a similar situation regarding the need to inspect the `Status` (of `Suites`) - or simply knowing at least one test failed or was aborted (amongst the suites).  Here's the background:  We have written our own REST API integration testing framework that uses Scalatest as the underlying testing / assertion framework.  We have a custom SBT plugin that invokes our framework and runs multiple suites, via the `Suites.execute(...)` method, to take advantage of printing the results to standard output.  

Currently the plugin always explicitly exits with a zero return code.  We would like to modify this so the appropriate code can be returned based on whether the suites passed or not.  Ultimately this is to facilitate scripting and automation.

Is there a way to do this?

Thanks,
Sujan Kapadia
Technology Consultant @ Chariot Solutions

Bill Venners

unread,
Oct 26, 2015, 11:46:36 AM10/26/15
to scalate...@googlegroups.com
Hi Sujan,

Suites.execute is intended for calling from the REPL mostly. If you need to know the exit status, that's run. What you can do is be inspired by the code of execute, which turns around and calls run, but throws away the Status. If you call status.succeeds on the returned Status, it will block until the suite has completed, then return true if no tests failed and no suites aborted, else returns false.

The downside with that approach is you'll likely want to copy some code over for things that aren't public (or write them yourself). Another way to try it is to call Runner.run, which takes command line arguments. That method will also block until the test suite has completed, and return true or false. What you need to pass in that case is command line args, i.e., Strings, which are documented in the Runner Scaladoc.

Bill

Sujan Kapadia

unread,
Oct 26, 2015, 12:44:08 PM10/26/15
to scalatest-users
Thanks for the prompt reply Bill!  I had already started taking a look at the implementation of the `execute` method as I had a feeling you'd suggest that :)

Thanks,
Sujan
Reply all
Reply to author
Forward
0 new messages