I have just started to learn C# and want to start testing using NUnit. I thought I would start very simple and test a "Hello World" program, just to get me used to NUnit in general.
Here is my code:
HelloWorld.cs
using System;
namespace TDDHelloWorld
{
public class HelloWorld
{
static void Main()
{
}
public static string HelloMessage()
{
return "Hello World";
}
}
}
HelloWorldTest.cs
using Microsoft.VisualStudio.TestPlatform.TestHost;
using NUnit.Framework;
using TDDHelloWorld;
namespace HelloWorldTests
{
[TestFixture]
public class HelloWorldTest
{
[Test]
public void SayHelloWorld()
{
string expected = "Hello World";
Assert.AreEqual(expected, HelloWorld.HelloMessage());
}
}
}
I have a few questions:
- What should be in my
static void Main {}? - The following error occurs:
Can't get source code location for : HelloWorldTests" -
what does this mean?
- Is this even correct? I am so new to C# I don't feel confident.
If it's relevant, I'm using Visual Studio Community on a MacBook. I've tried researching testing but struggling to grasp even the simplest test.
If anyone can help it would be really appreciated! :)
static void Mainis the initial method called in your CLI Application if you start the CLI Project. Could you share the source?