Hey guys!
I have to develop a simple Inhouse-Testframework.
For this task we have some test files (every file has one class and 1 to n test methods) in a given directory and we wont to execute all of them.
So i have a solution with 2 projects:
1: Console Application (TestRunner)
2: Class Library
The console application has a reference to the class library.
In the class library we have a Assert class and a method attribute ( SamwinTest )
In the following method i iterate over all files, compile them to a dll and want to execute them.
Private Sub RunTestFile(ByVal testFile As System.IO.FileInfo)
If Not System.IO.File.Exists(testFile.FullName) Then
Else
Try
Dim compilerParams As New System.CodeDom.Compiler.CompilerParameters()
compilerParams.OutputAssembly = System.IO.Path.Combine(App.Default.OutputFolder, String.Format("{0}.dll", testFile.Name))
Dim asm As System.Reflection.Assembly
For Each asm In AppDomain.CurrentDomain.GetAssemblies()
compilerParams.ReferencedAssemblies.Add(asm.Location)
Next
compilerParams.GenerateInMemory = False
compilerParams.GenerateExecutable = False
Dim compilerResult As System.CodeDom.Compiler.CompilerResults = _vbProvider.CompileAssemblyFromFile(compilerParams, {testFile.FullName})
Dim errorOccured As Boolean = False
If compilerResult.Errors.Count > 0 Then
errorOccured = True
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("compilation failed")
If App.Default.PrintErrorsInConsole Then
Console.WriteLine(Common.FormatError(compilerResult.Errors))
End If
Else
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("compilation passed")
End If
Console.ForegroundColor = ConsoleColor.White
If Not errorOccured Then
Dim testCase As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom(compilerParams.OutputAssembly)
For Each t In testCase.GetTypes()
Try
If t.Name.StartsWith("UnitTest") Then
Dim bindingFlag As System.Reflection.BindingFlags = System.Reflection.BindingFlags.DeclaredOnly Or
System.Reflection.BindingFlags.Public Or
System.Reflection.BindingFlags.NonPublic Or
System.Reflection.BindingFlags.Instance
Dim obj As Object = t.InvokeMember(t.Name, bindingFlag Or Reflection.BindingFlags.CreateInstance, Nothing, Nothing, Nothing)
For Each method In t.GetMethods()
Next
End If
Catch ex As Exception
Log(ex.ToString(), LogType.Err)
End Try
Next
End If
Catch ex As Exception
Log(ex.ToString(), LogType.Err)
End Try
End If
End Sub
Problem: it dont references the class library.
- Error message: "Type 'SamwinTest' is not defined
- Error message: "'Assert' is not declared. It may be inaccessible due its protection level
With the following code i thought that i add every assembly wich the console app refers.
Dim asm As System.Reflection.Assembly
For Each asm In AppDomain.CurrentDomain.GetAssemblies()
compilerParams.ReferencedAssemblies.Add(asm.Location)
Next
But i cant find the "Samwin.UnitTest.dll"
Here is just a simple and silly test class (test file)
Public Class Test
<SamwinTest()>
Public Sub HelloWorld()
Dim x As Integer
Dim y As Integer
Dim z As Integer
x = 1
y = 1
Assert.AreEqual(x, y)
z = x + y
End Sub
End Class
Anybody???
Thanks in adv
Cheers James