I am thinking on how to implement this , and seems like my knowledge is too poor to understand the implementation.
I have a code that compiles source code to DLL.
Then I need somehow to run Unit test on this Dll , and check 3-4 methods inside.
I am trying to run unit tests this way.
CompilerResults compileResults = codeProvider.CompileAssemblyFromSource(compilerParameters, new string[] { sourceCode });
Assembly myAssembly = compileResults.CompiledAssembly;
TestPackage testPackage = new TestPackage(@"TestingProject.dll");
testPackage.Assemblies.Add(myAssembly);
RemoteTestRunner remoteTestRunner = new RemoteTestRunner();
remoteTestRunner.Load(testPackage);
TestResult testResult = remoteTestRunner.Run(new NullListener(),TestFilter.Empty,false,LoggingThreshold.All);
And this for example Test
[Test]
public void AddTest(IDynamicScript s)
{
Assert.AreEqual(10, s.Add(5,5));
Assert.AreNotEqual(10,s.Add(4,5));
}
Since Assembly is compiled dynamically , I can't reference it to unit test Project , and it will not compile , any suggestions please on how to implement this please
Your code works just fine after a few modifications. These are the required changes:
nunit.framework.dll
assembly, which I got from the location of the copy loaded in the main AppDomain, but you can also reference it from the file system without loading it. Usually you will also need to supply the paths of the assemblies containing the code you're testingTestPackage
class takes an absolute path in its constructor, in this case I supplied the location of the generated assemblyThis is the code with the corrections: