asp.net mvc - How to test a message set by the build config? -


After

I have a string that is displayed on all my pages to indicate what mode was created in the system (i.e. debug Is, beta, release, etc.). The string is set by using the compiler's position (#if in VB), so that it will change based on what the build mode we are doing.

I use the condition of the compiler, for this was written like a test (actually in the live code), the problem is, under all my build makes me different without running, I can not verify the exact string generated for it all

Here is my code:.

  Public Sub AssertHasMessageForBuild () Dim Message String = None #if Debug then Message = "Debug Mode" #ElseIf Beta then #END as Message = "Beta" String.IsNullOrEmpty (Message) then Assert.AreEqual (Message, ViewData ("DebugMessage")) or else CollectionAssert.DoesNotContain (ViewData, "DebugMessage") end then End Sub    < P> 

TDD is not really a mechanism for great testing; With this help you have a mechanism to think about the design and responsibility of your classes.

You may want to separate the two responsibilities - In the mode you are able to explore, and build the message. Then you can do TDD to create the message, so that you can not easily tDD the only part of the mode detection system.

You can still test it manually, however. Sometimes this is the only way to go if you ever change it, just make sure you test it manually (you want to add a comment accordingly).

Comments