This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1384|Reply: 0

[Console Program] .NET/C# test code for multiple Main method solutions

[Copy link]
Posted on 2024-12-24 09:14:58 | | | |
Requirements: Generally, during the development process, programmers may encounter some problems, need to write simple test code for verification, and create a new console application. If we need to test 10 feature points and want to keep the tested code, do we want to build 10 console apps (too many solution projects), or one console app defines 10 methods to write different logic.

In order to reduce the number of items in the solution, facilitate code testing, and keep the code logic clean and clear, we can create multiple new class objects in one console, each with a Main method, as follows:



However, when compiling the project, an error will be reported as follows:

The program defines multiple entry points. Compile with /main (specifying the type that contains the entry point).

We edit the project configuration and set the StartupObject parameter to solve the problem, as shown in the figure below:



The configuration is as follows:


When testing, you can modify the object name according to your own scenario.

Reference:
The hyperlink login is visible.
The hyperlink login is visible.




Previous:.NET/C# is optimized with StackExchange.Redis performance
Next:DNSPod resolves priority tests based on geography
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com