osx - How to compile and run C# files with NUnit tests from the command line on a Mac, using mono -


i have 2 files. 1 test file, tests.cs:

using nunit.framework;  [testfixture] public class hellotest {     [test]     public void stating_something ()     {         assert.that(greeter.hello(), is.equalto("hello world."));     } } 

the other greeter.cs:

public class greeter {     public static string hello(string statement)     {         return "hello world.";     } } 

how run these command line on mac?

for simple script, can run:

mcs -out:script.exe script.cs mono script.exe 

but when try run mcs -out:tests.exe tests.cs, error: error cs0246: type or namespace name `nunit' not found. missing assembly reference?

and if fixed, tests file isn't referencing greeter file anyway, how make find it?

compile tests library, include reference nunit framework exists in gac, , add .cs:

mcs -target:library -r:nunit.framework -out:tests.dll greeter.cs tests.cs 

run tests nunit console runner:

nunit-console tests.dll 

remove string parameter match test:

public class greeter {     public static string hello()     {         return "hello world.";     } } 

fixed assert:

using nunit.framework;  [testfixture] public class hellotest {     [test]     public void stating_something ()     {         assert.areequal("hello world.", greeter.hello());     } } 

note: string testing should cultural aware, or use stringcomparison.invariantculture


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -