简体   繁体   English

C ++ .NET是否等效于Java公共静态void main()?

[英]C++ .NET equivalent to java public static void main()?

In java I can simply test classes directly with 在Java中,我可以直接使用

public static void main()

I then just add quick code and under Eclipse "Run" the class. 然后,我只添加快速代码,并在Eclipse下“运行”该类。 Is there anything similar in C++ .NET ? C ++ .NET中有类似的东西吗?

Right now I have to create an empty project, reference the correct headers then set that project as start up project. 现在,我必须创建一个空项目,引用正确的标题,然后将该项目设置为启动项目。

Unit tests . 单元测试 There's also the object test bench if you're using VS. 如果使用的是VS,则还有对象测试平台

I do this in C# so I don't know if this will react any differently, but I set up an empty "test" class with the main method and then set the project to startup with that class file. 我在C#中执行此操作,因此我不知道它是否会做出不同的反应,但是我使用main方法设置了一个空的“ test”类,然后将项目设置为使用该类文件启动。 You shouldn't have to create the file in a separate project. 您不必在单独的项目中创建文件。

I'm not terribly familiar with Eclipse but if you're just looking to run your objects in the IDE do the following. 我对Eclipse并不是很熟悉,但是如果您只是想在IDE中运行对象,请执行以下操作。

Open up the Immediate window and just call whatever function you want. 打开立即窗口,然后调用所需的任何函数。 This will start execute the code you type. 这将开始执行您键入的代码。 You will likely have to qualify the name. 您可能必须限定名称。 Ex: ClassLibrary1.MyClass.SomeMethod() 例如:ClassLibrary1.MyClass.SomeMethod()

I like using TestDriven.NET for this. 我喜欢为此使用TestDriven.NET It allows you to execute any public method by rightclicking on the header and selecting "Run test". 它允许您通过右键单击标题并选择“运行测试”来执行任何公共方法。

I like making 我喜欢做

public static void Test()

methods on dialog- and form-classes to use with this feature. 与该功能一起使用的对话框类和窗体类上的方法。

It supports C++/CLI, so if that is what you mean by C++.NET, it should work for you. 它支持C ++ / CLI,因此,如果这就是C ++。NET的含义,那么它应该对您有用。

Edit: You should only do that for things that are not automatically testable - such as pure GUI classes. 编辑:您应该只对无法自动测试的事物执行此操作-例如纯GUI类。 Otherwise I agree with the other commenters: use a unit test framework. 否则,我同意其他评论者的意见:使用单元测试框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM