JUnit-like package?

143 views
Skip to first unread message

Patrice Chalin

unread,
Apr 10, 2014, 5:48:12 PM4/10/14
to mi...@dartlang.org
Anyone aware if there are alternatives to unittest, or packages that build upon it that might offer an experience similar to JUnit.  DUnit seemed to exist as some point, but I can't find it anymore. Thanks, Patrice

Kevin Moore

unread,
Apr 11, 2014, 11:20:25 PM4/11/14
to mi...@dartlang.org
I've done some work recently to pull unittest into a few packages:

matcher: basic logic for testing conditions
mock: a basic mocking package
unittest: everything else

matcher would get you really far if you wanted to implement your own solution.

Ross Smith

unread,
Apr 12, 2014, 5:33:11 AM4/12/14
to mi...@dartlang.org
I have a package on pub named `bench` that builds upon the `unittest` package to offer xUnit style annotations and a reflective test runner:


What it lacks is the nice test runner that jUnit or nUnit have.  Those work by loading a jar / assembly and reflecting over the loaded classes.  This isn't possible in Dart (yet?).  I guess that a Dart solution will require a `spawnUri` on a dart file, and then set up some message passing between the test runner application and the user test scripts.  Another Dart solution would be a remote mirror system with invoke capabilities but I don't know if that is still planned or not.

So for now `bench` works by requiring an entry-point script such as:

```
import 'package:bench/bench.dart';
   
   // import your test libraries so that reflection can find them

void main() => reflectTests();
```  

The `reflectTests` function will use mirrors to find all test libraries, test functions, setup, teardown etc... and run everything.

cheers,

George Moschovitis

unread,
Apr 13, 2014, 2:14:22 PM4/13/14
to mi...@dartlang.org
unittest: everything else
 
can we finally see the rename to 'unit_test' ?
any chance to see unit(_)test support in DartEditor?

Anders Holmgren

unread,
Apr 13, 2014, 5:45:03 PM4/13/14
to mi...@dartlang.org
Actually WebStorm / Idea does this well. One of the reasons I'm keen to get it working again for my side project

George Moschovitis

unread,
Apr 14, 2014, 3:15:02 AM4/14/14
to mi...@dartlang.org
I use WebStorm at work, it's great.
But, I *really* like the simplicity of DartEditor, if only they fixed some small things (e.g. Ctrl+Shift+/, cross link to package project file, for 'path'-referenced packages, etc..) it would be dreamy :)

Patrice Chalin

unread,
Apr 15, 2014, 10:59:53 PM4/15/14
to mi...@dartlang.org
Kevin, Ross: thanks for your responses.

Ross: I only took a quick look at bench, it looks promising. Does it also work for @Test annotating methods inside classes or only top-level functions in libraries?

Ross Smith

unread,
Apr 16, 2014, 4:50:00 AM4/16/14
to mi...@dartlang.org
Hey Patrice,

> Ross: I only took a quick look at bench, it looks promising. Does it also work for @Test annotating methods inside classes or only top-level functions in libraries?

Currently it groups @Test top-level functions by library only.  I felt like libraries and top-level functions allowed me to write less boilerplate than classes / methods, but it otherwise works in a very similar fashion.  Top-level variables of the library can be used to store state from @Setup instead of instance members.

Another thing `bench` currently lacks is documentation :/  I recommend having a look at the test suites of some of my other Github projects if you're interested to see more concrete examples.

cheers,
Reply all
Reply to author
Forward
0 new messages