Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
In C++, when creating a Windows application which includes a form, there's a hotkey to test it before running the application (Ctrl+T).
Is there such a thing for C# forms?
Posted
Comments
Andy Lanng 17-Aug-15 4:31am    
That depends. If you have .Net Unit Tests, then yes. Otherwise you can set up a pre-compile command to run tests after compile
ilostmyid2 18-Aug-15 3:16am    
i'll try .net unit test. is it a utility?
how to setup a precompile command?
Andy Lanng 18-Aug-15 4:08am    
I'll write a quick solution

You can run your unit test using a different shortcuts in your unit test file, see this link for details https://msdn.microsoft.com/en-us/library/ms182470.aspx[^]

So if you exercise your form in unit tests you can
Your design surface will only execute the constructor, so if you wanna flip to and from your designer you'll have to do what you wanna test in the constructor, this is not widely used for that to my knowlege though.
 
Share this answer
 
Comments
ilostmyid2 18-Aug-15 3:17am    
i'm not expert in this context. would u explain pls?
Thomas Nielsen - getCore 18-Aug-15 3:49am    
With the risc of misundertanding your ambition, and because i've not been programming C++ for some 18 years :)
When in a unit test project you would genrally in C# want to provide som test data object, severing to the database and then instantiating for instance your form and exercise it. say your unit test class instantiates then makes your form. it will then run a part of functionality as you wish, repetedly for as many unit tests as you make with option to run code before and after each such.
if your cursor is within a test project "ctrl+r, a" will execute all tests, "ctrl+r, d" rerun last testrun and "ctrl+r, f" run all failed tests again "ctrl+r, t" runs the test your cursor is in or if outside testmethod all tests in this test class.
Much faster often, to run all unit tests before running, is this what you're trying to do?
Closest thing i know from VS C#
ilostmyid2 19-Aug-15 6:36am    
i answered in the following section.
Hi,
The following article will help you set up a unit test project within Visual Studio.
Creating Unit tests for your c# code[^]

Once you have your tests created then you can run them with Ctrl+R,A

These unit tests are also used in TDD when the tests are written first then the methods are written to accommodate them.
More on TTD here:
.NET TDD (Test Driven Development) by example - Part 1[^]



Running the tests will cause your code to compile anyway so you don't need build events:
But just as an FYI, you can set up pre-compile / post-compile commands in the project properties window under the Build Events. You can have advanced bat script here but I find it's best to just call a .bat file.
More on this here:
Open project properties[^]
Build Events tab[^]
Build Events key words[^]

Hope this helps ^_^
Andy
 
Share this answer
 
Comments
ilostmyid2 18-Aug-15 5:52am    
thanks to both
so i think simply testing a form just to see its aspect before running the program and examine how it really appears at run-time leads to a complex solution. i'm not familiar with "unit test" concept, and as i see after your comments, i've to investigate in it and improve my knowledge about it.
i'll begin with your links and hope to find interesting things.
Andy Lanng 18-Aug-15 6:16am    
Yeah, there are other aspects to testing. Unit testing tests code methods. Other types of testing are QA (Quality Assurance) and UAT (User Acceptance Testing). Both of these look at the form design, appearance and functionality and both require the human element.
Philippe Mori 18-Aug-15 12:34pm    
You already see the form while designing it... and most of what want to try like resizing or some special keyboard handling need code to be run anyway. Also C# compiler is so fast that you can try the form in the application in no time at all. Thus testing is not that much pertinent...
ilostmyid2 18-Aug-15 15:17pm    
consider a situation in which the code is not compilable. ie. when there're some errors in it. eg. when adding a whole new part which code is not yet complete.
i encountered this requirement when i saw the different is aspect while designing and when i run my program.
Philippe Mori 18-Aug-15 15:42pm    
You should not mix too much designing the UI and writing code at the same time... and you should never have much code that don't compile.

Thus not having a way to test form at design time is really not a big issue. And even if it were possible, it won't give you much more that what you see in the designer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900