1 | // ****************************************************************
|
---|
2 | // Copyright 2007, Charlie Poole
|
---|
3 | // This is free software licensed under the NUnit license. You may
|
---|
4 | // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
|
---|
5 | // ****************************************************************
|
---|
6 |
|
---|
7 | using System;
|
---|
8 | using System.Reflection;
|
---|
9 |
|
---|
10 | namespace NUnit.Core.Extensions
|
---|
11 | {
|
---|
12 | /// <summary>
|
---|
13 | /// SampleSuiteExtension is a minimal example of a suite extension. It
|
---|
14 | /// extends test suite and creates a fixture that runs every test starting
|
---|
15 | /// with "SampleTest..." Because it inherits from TestSuite, rather than
|
---|
16 | /// TestFixture, it has to construct its own fixture object and find its
|
---|
17 | /// own tests. Everything is done in the constructor for simplicity.
|
---|
18 | /// </summary>
|
---|
19 | class SampleSuiteExtension : TestSuite
|
---|
20 | {
|
---|
21 | public SampleSuiteExtension( Type fixtureType )
|
---|
22 | : base( fixtureType )
|
---|
23 | {
|
---|
24 | // Create the fixture object. We could wait to do this when
|
---|
25 | // it is needed, but we do it here for simplicity.
|
---|
26 | this.Fixture = Reflect.Construct( fixtureType );
|
---|
27 |
|
---|
28 | // Locate our test methods and add them to the suite using
|
---|
29 | // the Add method of TestSuite. Note that we don't do a simple
|
---|
30 | // Tests.Add, because that wouldn't set the parent of the tests.
|
---|
31 | foreach( MethodInfo method in fixtureType.GetMethods(
|
---|
32 | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly ) )
|
---|
33 | {
|
---|
34 | if ( method.Name.StartsWith( "SampleTest" ) )
|
---|
35 | this.Add( new NUnitTestMethod( method ) );
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|