Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: pkg/analysis_server/test/declarative_tests.dart

Issue 228013003: Use mirrors and annotations to find test methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analysis_server/test/protocol_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 library declarative_tests;
2
3 import 'dart:mirrors';
4
5 import 'package:unittest/unittest.dart' show group, test;
6
7 /// Use [runTest] annotation to indicate that method is a test method.
8 /// Alternatively method name can have the `test` prefix.
9 const runTest = const _RunTest();
10
11 class _RunTest {
12 const _RunTest();
13 }
14
15 /// Creates a new named group of tests with the name of the given [Type], then
16 /// adds new tests using [addTestMethods].
17 addTestSuite(Type type) {
18 group(type.toString(), () {
19 addTestMethods(type);
20 });
21 }
22
23 /// Creates a new test case for the each static method with the name starting
24 /// with `test` or having the [runTest] annotation.
25 addTestMethods(Type type) {
26 var typeMirror = reflectClass(type);
27 typeMirror.staticMembers.forEach((methodSymbol, method) {
28 if (_isTestMethod(method)) {
29 var methodName = MirrorSystem.getName(methodSymbol);
30 test(methodName, () {
31 typeMirror.invoke(methodSymbol, []);
32 });
33 }
34 });
35 }
36
37 bool _isTestMethod(MethodMirror method) {
38 if (method.parameters.isNotEmpty) {
39 return false;
40 }
41 var methodSymbol = method.simpleName;
42 // name starts with "test"
43 var methodName = MirrorSystem.getName(methodSymbol);
44 if (methodName.startsWith('test')) {
45 return true;
46 }
47 // has @testMethod
48 return method.metadata.any((annotation) {
49 return identical(annotation.reflectee, runTest);
50 });
51 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/protocol_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698