Last month at the AkronCodeClub they selected the magic square kata, which was a new one for me. Basically, you arrange 9 unique numbers in a 3x3 grid such that they add up to the same number horizontally, vertically and diagonally. Caesars casino free spins. I paired up with someone else who knew C#, so it was a good opportunity to try doing the kata in Visual Studio for Mac!
Visual Studio 2019 for Mac allows you to easily launch multiple instances of the IDE from the macOS dock, enabling you to work on multiple solutions simultaneously, one per instance. Xamarin tools Developers run though the 'build, deploy, debug' cycle countless times in any given day. Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows. Download Visual Studio Code to experience a redefined code editor, optimized for building and debugging modern web and cloud applications.
Although I've kicked the tires on VS4Mac a bit, one of the things I hadn't tried testing out was, well. testing!
Method 1: An NUnit Library Project
The easiest method is to just create a new 'NUnit Library Project'. The VS4Mac team actually added a project type that includes the NUnit package and a test file out of the box. How convenient is that??
Create a new project
Go to: File / New Solution / Other / .NET / NUnit Library Project
Create a class and some tests
Like I said, there's already a 'Test.cs' file ready to go, with the proper NUnit attributes and everything. Go ahead and create a regular class and add a couple tests against it.
Run the tests
If you can't see the 'Unit Test' pane (or pad as they call it on the Mac), open it now: View / Pads / Unit Tests
You may need to click the build button (black triangle in upper-left) to see your new tests. Or just click the 'Run All' button in the Unit Tests pad.
Now change the logic so the tests fail (if they didn't already) and you can see the failure results in the 'Test Results' pad at the bottom. If you don't see that pad, open it now: View / Pads / Test Results
That's it! If you're using VS4Mac for TDD during a code kata, it doesn't get much easier than that. :)
Method 2: Add NUnit to an Existing Project
But what if you already have a project and now you want to add tests to it? http://lphfpr.xtgem.com/Blog/__xtblog_entry/19080002-ancient-planet-1-0-23#xt_blog. Let's start by creating a Library project to act as the 'existing project': File / New Solution / Other / .NET / Library
You should have a blank screen, along with the 'Solution' pad on the side of the screen. If you don't see that pad, go to: View / Pads / Solution
Create a Test File
Right-click your project and choose Add / New File. Select General / Empty Class and name it 'MagicSquareTests.cs'. I also repurposed the default 'MyClass.cs' as my MagicSquare class. You should end up with something like this:
Add the NUnit Package via NuGet
Right-click on Packages in the Solution pad and choose 'Add Packages'. All you need is NUnit - don't bother with the NUnit Console Runner.
You should see NUnit under the Packages folder.
Create a Few Tests
Add some new tests to run against whatever logic your old project has. In my case, I added a single function for the magic square kata, and wrote a couple tests against it that I was sure would fail.
The test runner tells you what failed and where.
Run / Observe / Fix / Repeat!
Try adding enough code to get your tests to pass, and run again.
More Reading
If you'd like, you can read more about what I've discovered.. or just download Visual Studio for Mac and try it out yourself!
Visual Studio has not always been as user-friendly on the Mac as it is on a Windows machine. Lately, however, the stable release of VS for Mac is really starting to feel like a simple, but luxurious cousin to Visual Studio 2019. Different, but related. Installation on a Mac is quick, simple, and allows you to get into coding right away - whether you are already familiar or an Apple-only dev getting into something new like Xamarin.
Visual Studio for Mac bears a striking similarity to xCode's solution navigation feel, but brings the power of VS intellisense and an ability to focus on your code in a much cleaner looking environment. In my opinion, this brings the best of both worlds together. But don't take my word for it: here are five reasons to give Visual Studio for Mac another go!
1. The C# Editor in Visual Studio for Mac is Completely New
Roslyn, the .NET compiler platform, is now in the Visual Studio for Mac editor - making your intellisense as powerful as its big brother on Windows. Marrying the functionality ported over from the Roslyn compiler with the (frankly, beautiful looking) simplicity of a native-feeling Mac UI editing experience gives this girl all the feels. It has full support for third-party Nuget packages for .NET Core (utilizing .NET Standard) along with Unity, Xamarin and Cocoa apps.
I didn't notice a big difference gating my progress of a .NET Core app. At this point, I don't know why I would switch over to a windows VM in order to build a microservice API in .NET Core at all!
Finally, I'm loving that VS for Mac now includes 'Go to implementation' as an option in the latest release. Exciting! The C# experience is pretty great now.
2. CLI Developers Can Open .NET Core Projects in Terminal
Ah, the command line. Many developers love using it for .NET Core instead of the 'visual' click and drag aspect of the Visual Studio IDE. At first, the use of command line programming with ASP.NET Core was the only way you could build those apps. Over time, and especially with the release of Visual Studio 2019, the File > New Project templates for ASP.NET Core apps have been baked into the install bringing a truly visual experience to that build.
For a while, it was unclear if the same command line net new project CLI functionality would be available on Mac, but I am happy to report that it is and it works beautifully! The use of the Terminal app brings that experience to you harcore command line devs.
Visual Studio 2017 For Mac
3. Improved Build Time for Xamarin
Remember those build and deploy coffee breaks? Well say goodbye (unless you don't want to of course). On one of my Xamarin projects I saw a super impressive 30% faster incremental build time. That's not an insignificant improvement.
This metric is also supported by the April 2019 press release from the VS for Mac team. I used to design my development process in such a way that I could multitask to stay efficient and productive. I'm happy to report those days are gone with much improved build speeds, making the Xamarin app building process something I can say I truly enjoy.
4. .NET Core 3 Support Available Right Out of the Gate
Does Visual Studio 2019 have .NET Core 3 support? Yes, but that's no reason to jump over to your Windows machine! You can use all the same, wonderful new stuff on your Apple machine, too.
In fact, I'd argue that Visual Studio for Mac is an excellent place to start learning how to build apps for .NET Core 3. With fewer small windows everywhere like it's Windows-based cousin, VS for Mac allows for a more-focused process.
5. Robust Source Control Options
This is where some 'same but different' comes into play. I find that developers coming over from Swift or Objective C development enjoy the experience of source control within Visual Studio for Mac. While there IS a difference in the process for Windows users, I don't find it particularly difficult. Visual Studio for Mac supports Git and Subversion built into the IDE, as well as TFS with a little more effort.
I have used the Github Desktop app for source control of my folders without much issue. This is also my source control workflow for VS Code, and while it is not integrated into the IDE of VS for Mac, it's also not a bad option. For the hardcore command line peeps, you can alternatively use Git inside the CLI tool Terminal, which is native to Apple OS. There is no learning curve here at all for developers who use command line.
Who Should Use Visual Studio for Mac?
Visual Studio for Mac is a strong choice for many developers and many use cases. Here are a few that come to mind:
Visual Studio 2019 For Mac
.NET users building Xamarin mobile apps that require IOS builds will benefit tremendously from having all their development on a single machine.
Developers working with .NET Core, who love working on a Mac, and currently use a virtual machine or Bootcamp to run Visual Studio in a windows environment will benefit from not having to switch over from the Apple operating system constantly.
Unity game developers will find VS for Mac be very intuitive option.
The last group to come over will be .NET Framework developers who have worked with Visual Studio on Windows as their only option for .NET 4.7.2 for example. Sadly no, .NET Framework cannot run on VS for Mac. However, once you are ready to start building your apps or microservices in .NET Core - check it out!
New functionality, extensions and templates are all coming this next year to Visual Studio for Mac that make living in harmony with Apple + Microsoft a real joy.
Learn More About .NET Core, Xamarin, Apple & OAuth
If you'd like to learn more about ASP.NET, Xamarin, or Apple, we've also published a number of posts that might interest you:
For other great content from the Okta Dev Team, follow us on Twitter and Facebook!