[英]Rider NUnit Test problem: Program does not contain main
I can't start my NUnit testing on Rider (JetBrains).我无法在 Rider (JetBrains) 上开始我的 NUnit 测试。 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.
我有一个名为 ISDI 的控制台应用程序项目,我正在尝试在同一解决方案中使用一个名为 ISDITest 的 NUnit 测试项目对其进行测试。
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
程序不包含适合入口点的 static 'Main' 方法
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.我认为测试 class 中的测试方法不需要 Main 并且我不知道如何解决这个问题,因为我在创建它时已经指定这是一个测试项目。 I'm sorry if this is a stupid question but I'm just getting started with C# and testing.
如果这是一个愚蠢的问题,我很抱歉,但我刚刚开始使用 C# 和测试。
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.通常,
Main
用于此目的,但是当您拥有NUnit
时,您可以使用[Test]
作为入口点。
When you want to run tests, you need to use the [Test]
flag as the point of entry for the program.当您想运行测试时,您需要使用
[Test]
标志作为程序的入口点。 You do not need a Main
method for this.您不需要
Main
方法。
I recommend reading the Rider / Unit Testing documentation for more information on how to run your [Test]
code without implementing a Main
method.我建议阅读 Rider / Unit Testing 文档以获取有关如何在不实现
Main
方法的情况下运行[Test]
代码的更多信息。
https://www.jetbrains.com/help/rider/Unit_Testing__Index.html https://www.jetbrains.com/help/rider/Unit_Testing__Index.html
Solved this putting an empty Main in the project I wanted to test.解决了这个问题,在我想测试的项目中放置一个空的 Main。 Still, it does not make any sense to me.
不过,这对我来说没有任何意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.