ALU
ALU

Reputation: 374

Rider NUnit Test problem: Program does not contain main

I can't start my NUnit testing on Rider (JetBrains). I have a Console Application project named ISDI and I'm tryin to Test it with a NUnit testing project named ISDITest in the same solution.

This is my code:

using System;
using ISDI; 
using NUnit.Framework;

namespace ISDITest {
    [TestFixture]
    public class TestNome
    {
        [Test]
        public void TestRoom()
        {
            IRoom r = new Room(0);
            IEntity p = new Player();
            r.InsertEntity(p);
            Assert.Equals(r.GetEntities().Count, 1);
            Assert.True(r.GetEntities().Contains(p));
        }
    }
 }

When I try to run the test I get a build error:

Program does not contain a static 'Main' method suitable for an entry point

I think testing methods in a testing class would not need a Main and I don't know how to solve this as I already specified that this is a Testing project when I created it. I'm sorry if this is a stupid question but I'm just getting started with C# and testing.

Upvotes: 1

Views: 1150

Answers (2)

CEH
CEH

Reputation: 5909

When running a program, you need an entry point - a place for the code to start. Usually, Main is used for this, but when you have NUnit, you can use a [Test] as an entry point.

When you want to run tests, you need to use the [Test] flag as the point of entry for the program. You do not need a Main method for this.

I recommend reading the Rider / Unit Testing documentation for more information on how to run your [Test] code without implementing a Main method.

https://www.jetbrains.com/help/rider/Unit_Testing__Index.html

Upvotes: 1

ALU
ALU

Reputation: 374

Solved this putting an empty Main in the project I wanted to test. Still, it does not make any sense to me.

Upvotes: 1

Related Questions