@@ -30,37 +30,63 @@ public void ServiceIsStarted()
30
30
Assert . That ( _driverService . Status , Is . EqualTo ( ServiceStatus . Started ) , "Failed to start service" ) ;
31
31
}
32
32
33
+ [ TestCaseSource ( nameof ( DriverSelectionTestCases ) ) ]
34
+ public void CorrectDriverIsUsed ( string fileName , bool skipNonTestAssemblies , Type expectedType )
35
+ {
36
+ var driver = _driverService . GetDriver ( AppDomain . CurrentDomain , Path . Combine ( TestContext . CurrentContext . TestDirectory , fileName ) , null , skipNonTestAssemblies ) ;
37
+ Assert . That ( driver , Is . InstanceOf ( expectedType ) ) ;
38
+ }
33
39
34
- #if NET5_0_OR_GREATER
35
- [ TestCase ( "mock-assembly.dll" , false , typeof ( NUnitNetCore31Driver ) ) ]
36
- [ TestCase ( "mock-assembly.dll" , true , typeof ( NUnitNetCore31Driver ) ) ]
37
- //[TestCase("notest-assembly.dll", false, typeof(NUnitNetCore31Driver))]
40
+ static TestCaseData [ ] DriverSelectionTestCases = new [ ]
41
+ {
42
+ #if NETFRAMEWORK
43
+ new TestCaseData ( "mock-assembly.dll" , false , typeof ( NUnit3FrameworkDriver ) ) ,
44
+ new TestCaseData ( "mock-assembly.dll" , true , typeof ( NUnit3FrameworkDriver ) ) ,
45
+ new TestCaseData ( "notest-assembly.dll" , false , typeof ( NUnit3FrameworkDriver ) ) ,
46
+ #elif NET5_0_OR_GREATER
47
+ new TestCaseData( "mock-assembly.dll" , false , typeof ( NUnitNetCore31Driver ) ) ,
48
+ new TestCaseData ( "mock-assembly.dll" , true , typeof ( NUnitNetCore31Driver ) ) ,
49
+ //new TestCaseData("notest-assembly.dll", false, typeof(NUnitNetCore31Driver)),
38
50
#elif NETCOREAPP3_1
39
- [ TestCase ( "mock-assembly.dll" , false , typeof ( NUnitNetCore31Driver ) ) ]
40
- [ TestCase ( "mock-assembly.dll" , true , typeof ( NUnitNetCore31Driver ) ) ]
41
- [ TestCase ( "notest-assembly.dll" , false , typeof ( NUnitNetCore31Driver ) ) ]
51
+ new TestCaseData( "mock-assembly.dll" , false , typeof ( NUnitNetCore31Driver ) ) ,
52
+ new TestCaseData ( "mock-assembly.dll" , true , typeof ( NUnitNetCore31Driver ) ) ,
53
+ new TestCaseData ( "notest-assembly.dll" , false , typeof ( NUnitNetCore31Driver ) ) ,
54
+ // TODO: This is never used. We need to test net standard driver in some way, possibly
55
+ // by forcing it's use in a separate test.
42
56
#elif NETCOREAPP2_1
43
- [ TestCase ( "mock-assembly.dll" , false , typeof ( NUnitNetStandardDriver ) ) ]
44
- [ TestCase ( "mock-assembly.dll" , true , typeof ( NUnitNetStandardDriver ) ) ]
45
- [ TestCase ( "notest-assembly.dll" , false , typeof ( NUnitNetStandardDriver ) ) ]
46
- #else
47
- [ TestCase ( "mock-assembly.dll" , false , typeof ( NUnit3FrameworkDriver ) ) ]
48
- [ TestCase ( "mock-assembly.dll" , true , typeof ( NUnit3FrameworkDriver ) ) ]
49
- [ TestCase ( "notest-assembly.dll" , false , typeof ( NUnit3FrameworkDriver ) ) ]
50
- #endif
51
- [ TestCase ( "mock-assembly.pdb" , false , typeof ( InvalidAssemblyFrameworkDriver ) ) ]
52
- [ TestCase ( "mock-assembly.pdb" , true , typeof ( InvalidAssemblyFrameworkDriver ) ) ]
53
- [ TestCase ( "junk.dll" , false , typeof ( InvalidAssemblyFrameworkDriver ) ) ]
54
- [ TestCase ( "junk.dll" , true , typeof ( InvalidAssemblyFrameworkDriver ) ) ]
55
- [ TestCase ( "nunit.engine.core.dll" , false , typeof ( InvalidAssemblyFrameworkDriver ) ) ]
56
- [ TestCase ( "nunit.engine.core.dll" , true , typeof ( SkippedAssemblyFrameworkDriver ) ) ]
57
- #if ! NET5_0_OR_GREATER // Not yet working
58
- [ TestCase ( "notest-assembly.dll" , true , typeof ( SkippedAssemblyFrameworkDriver ) ) ]
57
+ new TestCaseData( "mock-assembly.dll" , false , typeof ( NUnitNetStandardDriver ) ) ,
58
+ new TestCaseData ( "mock-assembly.dll" , true , typeof ( NUnitNetStandardDriver ) ) ,
59
+ new TestCaseData ( "notest-assembly.dll" , false , typeof ( NUnitNetStandardDriver ) ) ,
59
60
#endif
60
- public void CorrectDriverIsUsed ( string fileName , bool skipNonTestAssemblies , Type expectedType )
61
+ // Invalid cases should work with all target runtimes
62
+ new TestCaseData ( "mock-assembly.pdb" , false , typeof ( InvalidAssemblyFrameworkDriver ) ) ,
63
+ new TestCaseData ( "mock-assembly.pdb" , true , typeof ( InvalidAssemblyFrameworkDriver ) ) ,
64
+ new TestCaseData ( "junk.dll" , false , typeof ( InvalidAssemblyFrameworkDriver ) ) ,
65
+ new TestCaseData ( "junk.dll" , true , typeof ( InvalidAssemblyFrameworkDriver ) ) ,
66
+ new TestCaseData ( "nunit.engine.core.dll" , false , typeof ( InvalidAssemblyFrameworkDriver ) ) ,
67
+ new TestCaseData ( "nunit.engine.core.dll" , true , typeof ( SkippedAssemblyFrameworkDriver ) )
68
+ //#if !NET5_0_OR_GREATER // Not yet working
69
+ // new TestCaseData"notest-assembly.dll", true, typeof(SkippedAssemblyFrameworkDriver))
70
+ //#endif
71
+ } ;
72
+
73
+ [ Test ]
74
+ public void EnsureWeHaveSomeValidTestCases ( )
61
75
{
62
- var driver = _driverService . GetDriver ( AppDomain . CurrentDomain , Path . Combine ( TestContext . CurrentContext . TestDirectory , fileName ) , null , skipNonTestAssemblies ) ;
63
- Assert . That ( driver , Is . InstanceOf ( expectedType ) ) ;
76
+ // We currently build these tests for net462, net 8.0, net 6.0 and net core 3.1.
77
+ // This test is needed because of the conditional compilation used in generating
78
+ // the test cases. If the test project is updated to add a new target runtime,
79
+ // and no test cases are added for that runtime, this test will fail.
80
+ foreach ( var testcase in DriverSelectionTestCases )
81
+ {
82
+ // Third argument is the Type of the driver
83
+ var driverType = testcase . Arguments [ 2 ] as Type ;
84
+ if ( ! ( driverType . BaseType == typeof ( NotRunnableFrameworkDriver ) ) )
85
+ break ;
86
+
87
+ // All expected drivers derive from NotRunnableFrameworkDriver
88
+ Assert . Fail ( "Only invalid test cases were provided for this runtime. Update DriverServiceTests.cs to include some valid cases." ) ;
89
+ }
64
90
}
65
91
}
66
92
}
0 commit comments