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

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

Issue 349103003: Migrate protocol_test.dart to reflective tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 /**
8 * Use [runTest] annotation to indicate that method is a test method.
9 * Alternatively method name can have the `test` prefix.
10 */
11 const runTest = const _RunTest();
12
13 class _RunTest {
14 const _RunTest();
15 }
16
17 /**
18 * Creates a new named group of tests with the name of the given [Type], then
19 * adds new tests using [addTestMethods].
20 */
21 addTestSuite(Type type) {
22 group(type.toString(), () {
23 addTestMethods(type);
24 });
25 }
26
27 /**
28 * Creates a new test case for the each static method with the name starting
29 * with `test` or having the [runTest] annotation.
30 */
31 addTestMethods(Type type) {
32 var typeMirror = reflectClass(type);
33 typeMirror.staticMembers.forEach((methodSymbol, method) {
34 if (_isTestMethod(method)) {
35 var methodName = MirrorSystem.getName(methodSymbol);
36 test(methodName, () {
37 typeMirror.invoke(methodSymbol, []);
38 });
39 }
40 });
41 }
42
43 bool _isTestMethod(MethodMirror method) {
44 if (method.parameters.isNotEmpty) {
45 return false;
46 }
47 var methodSymbol = method.simpleName;
48 // name starts with "test"
49 var methodName = MirrorSystem.getName(methodSymbol);
50 if (methodName.startsWith('test')) {
51 return true;
52 }
53 // has @testMethod
54 return method.metadata.any((annotation) {
55 return identical(annotation.reflectee, runTest);
56 });
57 }
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