Sammy Berry
Sammy Berry

Reputation: 23

C# TestClass on Mac

I am trying to get a file working on OS X which requires the use of the [TestClass()] and [TestMethod()] attributes. Im new to c# (Ive used java for a few years now) so Im not sure, but I think these attributes are part of Microsoft.VisualStudio. Since I'm on OS X I an using mono to compile and run C# files. How, if possible, can I get the same functionality as the Microsoft.VisualStudio.TestTools.UnitTesting namespace?

Upvotes: 2

Views: 1044

Answers (2)

Bob The Janitor
Bob The Janitor

Reputation: 20802

[TestClass()] and [TestMethod()] are part of MSTest framework and are not available in Mono.

Have you looked at using a mono build of Nunit you can also use "using mapping" to convert you ms test attributes to nunit here is an example http://www.martinwilley.com/net/code/nunitmstest.html

If using mono isn't a requirement, you could also look at using .NET Core it's still in development but it's the full .net stack by Microsoft for OSX and Linux

Upvotes: 0

shturm
shturm

Reputation: 867

Xamarin Studio / Monodevelop has a unit testing add-in which allows running NUnit tests within the IDE. The add-in should be installed by default. If not, you can install it through Tools > Add-ins.

When you build a class that has [TestFixture] attribute and it has a method with [Test] attribute - you can run it from View > Pads > Unit Tests or green icon at signature line. In this screenshot, lines 12 and 26:

enter image description here

Additionally, there should be a project template which already has NUnit package pre-installed and a test class ready: enter image description here

Upvotes: 1

Related Questions