Test-Driven Test Development

Making it Go Green

Run the Integration Test

Back in the MiniSpec.Specs project, add project references for MiniSpec and MyTests:

cd MiniSpec.Specs/
dotnet add reference ../MiniSpec
dotnet add reference ../MyTests

Now run the tests with dotnet test (excerpt below)

IntegrationTest.ExpectedSpecsPassAndFail [FAIL]
  Failed IntegrationTest.ExpectedSpecsPassAndFail]
  Error Message:
   Assert.Contains() Failure
Not found: PASS TestShouldPass   <---- What We Expected
In value:  Hello World!          <---- Actual Value
  Stack Trace:
     at IntegrationTest.ExpectedSpecsPassAndFail()
Failed!  - Failed:     1, Passed:     0, Skipped:     0, Total:     1

Ah ha! The test looked for "PASS TestShouldPass" but found "Hello World!"

This is fabulous, it means that minispec.exe is running correctly!

Take a look at the generated Program.cs in the new MiniSpec project:

using System;

namespace MiniSpec
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

This is where the "Hello World!" value is coming from.

Update MiniSpec Program.cs

Try updating MiniSpec/Program.cs to the following:

using System;

Console.WriteLine($"Received Args: {string.Join(", ", args)}");

Where’s the Main method?
C# 9 supports top-level statements used in one file to define your main program more easily.

And now, still from MiniSpec.Specs/, run dotnet test again to see the change:

$ dotnet test
...
Not found: PASS TestShouldPass
In value:  Received Args: MyTests.dll
...

Wonderful. Ok. Our program runs. It gets a list of DLLs. Now let’s run the tests in the DLLs!