It is too troublesome to test the function of a single page in web development. After entering the username and password from the homepage, you can only get to the page you want to test after some operations. (In fact, no matter what development you do, testing a single function is very troublesome). With a cautious attitude, I usually like to write a few paragraphs and test them once. It is obviously very uneconomical to start the entire project to test every time.
I usually add a new configuration for testing in the Solution, add a compilation directive such as "Test" in it, and then put some test conditions and test methods under this directive in the code. When the development team has not introduced concepts such as unit testing, I don't want to do this kind of thing by adding a new test project. And for situations like a single Page under the Web, I don't know how to proceed. Therefore, it is more familiar to use my own compilation instructions in the past.
(When I used to write some non-WEB things, I also liked to write the test method and the class itself in a file, and then use compilation instructions to distinguish them. If you want to test, just select "Test" directly in the development environment. That configuration, and then start TestDriven to test it. It saves a lot of effort on the machine without starting the entire project. TestDriven is very useful.
If you are developing in C#, in the development environment, if the current compilation conditions are not met, those codes will be grayed out and can be indented, which is not an eyesore at all)
However, my tricks no longer work under VS2005. Now WEB development is a little different from before. I can't find a place to add compilation instructions when I search it. Non-WEB developers can still find a place to add them. After struggling for a long time, I found that now I have put some settings in Web.config, and conditional compilation is no exception.
For example, now we need to add a "Test" conditional compilation directive. In the Web.config file, just add the following statement under the <compilation> section.
<compilers>
<compiler language="vb"
type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"
extension=".VB"
compilerOptions="/define:Debug=True /define:Trace=True /define:Test=True "/>
<compiler language="c#"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"
extension=" .cs"
compilerOptions="/d:DEBUG;TRACE;Test"/>
</compilers>
It's very important to add a <compiler> for each language. Of course, if the corresponding language is not used in the project, you can ignore it or delete it. Generally, C# and VB are used more often, but I only use these two.
After setting it in Web.config, there is no need to define compilation instructions on each page that needs to be tested. However, it is still not as good as before. In the past, it was enough to directly select the configuration on the IDE toolbar. Now I have to write so many things, and mainly Still inconvenient to switch. For example, if I don't want to start under the "Test" condition, I have to go to Web.config and comment out the above paragraph.
According to MSDN, under .Net 2.0, the <compiler> element is deprecated. My approach does not seem to be the right way.