The problem is related to the fact that views are only compiled when you run your application so the TEST
symbol that you defined is no longer applied by the compiler because it has no knowledge of it.
Assuming that you are using C# you need to configure the compiler to use the TEST
symbol when building the views and for this you need to override its configuration in Web.config
using the following:
<system.codedom>
<compilers>
<compiler
language="c#;cs;csharp"
extension=".cs"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
compilerOptions="/define:TEST"
warningLevel="1" />
</compilers>
</system.codedom>
The important part is that you define compilerOptions="/define:TEST"
. The rest of the configuration you need to adapt to your specific needs, for example switch between .NET 2.0 or .NET 4.0.
If you apply this directly in the Web.config
it will work but will define TEST
every time. So what you should really do is use Web.config transformations so that the symbol is only applied for the correct build configurations.