i have following method needs render view (this view not exist).
public class homecontroller : controller { public actionresult gettestpage() { return partialview("~/views/admin/testpage.cshtml"); } } i have following test method in separate class.
[testclass()] public class homecontrollertests : controller { [testmethod()] public void gettestpagetest() { homecontroller hc = new homecontroller(); actionresult actual = null; try { actual = hc.gettestpage(); } catch (exception e) { system.diagnostics.debug.writeline("exception caught, test fail: " + e.tostring()); assert.fail(); } assert.isnotnull(actual); } } currently test passes, shouldn't. know can break build setting <mvcbuildview> tag true in .csproj file.
however, have unit test (using ms testing environment in vs 2012) test if view compiles/exists/sends response.
what best way this?
thanks!
the test not fail because partialview method of controller returning object of type partialviewresult containing view name supplied in viewname property. when mvc engine sees object says "ok, it's partialviewresult i'm supposed render view points to", , then crashes if file not exist. of course not happen in unit test.
an option test phisically check file exists (you need of course path manipulation convert relative ~/... view path relative or absolute path within project). don't know if there's else can do.
Comments
Post a Comment