{"id":398,"date":"2014-12-19T12:11:29","date_gmt":"2014-12-19T11:11:29","guid":{"rendered":"http:\/\/dev.flauschig.ch\/wordpress\/?p=398"},"modified":"2014-12-19T12:11:29","modified_gmt":"2014-12-19T11:11:29","slug":"using-travis-ci-in-github-with-c-and-nunit-tests","status":"publish","type":"post","link":"http:\/\/dev.flauschig.ch\/wordpress\/?p=398","title":{"rendered":"Using Travis CI in GitHub with C# and NUnit Tests"},"content":{"rendered":"<p>I finally started using <a href=\"https:\/\/github.com\/Roemer\" target=\"_blank\">GitHub<\/a> for some of my projects. And as usual, I try what is possible \ud83d\ude09<br \/>\nThis time, I played around with Continuous Integration. The way to go seems to be with <a href=\"https:\/\/travis-ci.org\" target=\"_blank\">Travis CI<\/a>. It has (beta) support for .Net with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Mono_(software)\" target=\"_blank\">Mono<\/a>. And it seems to work quite well as long as your projects are Mono compliant.<\/p>\n<p><strong>Basic Travis usage in github<\/strong><br \/>\nTo use Travis in github is pretty straight forward. Just register for Travis, link to your github and add a <code>.travis.yml<\/code> file to your github project.<br \/>\nThe basic file can look like:<\/p>\n<pre class=\"lang:default decode:true \" >language: csharp\r\nsolution: src\/&lt;yoursolution&gt;.sln<\/pre>\n<p>This just compiles all the projects which are in your solution.<\/p>\n<p><strong>Skip \/ fix unsupported code when compiling with Mono<\/strong><br \/>\nIf you&#8217;re project is almost Mono compliant, you can think of using the precompiler directive with the variable <code>__MonoCS__<\/code> to get it to build on mono as well but use the &#8220;real&#8221; thing in your Visual Studio.<br \/>\nHere&#8217;s an example which uses the CommandManager of WPF which does not exist in Mono:<\/p>\n<pre class=\"lang:c# decode:true \" title=\"Precompiler directive to disable unsupported code in Mono\" >#if __MonoCS__\r\n        public event EventHandler CanExecuteChanged;\r\n#else\r\n        public event EventHandler CanExecuteChanged\r\n        {\r\n            add { CommandManager.RequerySuggested += value; }\r\n            remove { CommandManager.RequerySuggested -= value; }\r\n        }\r\n#endif<\/pre>\n<p>This makes at least sure, that it compiles on Mono.<\/p>\n<p><strong>Using nUnit tests with Travis<\/strong><br \/>\nTo run nUnit tests with travis is also fairly easy. Just add your unittest project and modify the Travis file like this:<\/p>\n<pre class=\"lang:default decode:true \" >language: csharp\r\nsolution: .\/src\/yoursolution.sln\r\n\r\ninstall:\r\n  - sudo apt-get install nunit-console\r\n  - nuget restore .\/src\/yoursolution.sln\r\n\r\nscript:\r\n  - xbuild .\/src\/yoursolution.sln\r\n  - nunit-console .\/src\/SomeLibrary.Tests\/bin\/Debug\/SomeLibrary.Tests.dll\r\n<\/pre>\n<p>This installs the nunit-console package, makes sure that the nuget libraries are fetched, compiles your solution with xbuild and runs the test library with nunit-console.<\/p>\n<p>That&#8217;s it. Now Travis compiles and tests your github project and fails in case that it can&#8217;t compile or at least one unit test fails.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I finally started using GitHub for some of my projects. And as usual, I try what is possible \ud83d\ude09 This time, I played around with Continuous Integration. The way to go seems to be with Travis CI. It has (beta) support for .Net with Mono. And it seems to work quite well as long as &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3],"tags":[],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-roemer","4":"post-398","6":"format-standard","7":"category-programming"},"acf":[],"views":3193,"_links":{"self":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/398"}],"collection":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=398"}],"version-history":[{"count":0,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/398\/revisions"}],"wp:attachment":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}