2

モックを使用せずにテスト プロジェクトからビューをテストするにはどうすればよいですか? 私はあらゆる種類のことを試しました。MarshalByRefObject を介して ASP .NET アプリケーション ホストを作成し、その ViewToString メソッドを使用します。また、ViewPage オブジェクトを動的にインスタンス化しようとしましたが、うまくいきませんでした。

Test method Fablelane.WebApplication.Tests.UseCases.CreateNewSchoolAsAdministrator threw exception: 
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.VirtualPath.GetCacheKey()
at System.Web.Compilation.BuildManager.GetCacheKeyFromVirtualPath(VirtualPath virtualPath, ref Boolean keyFromVPP)
at System.Web.Compilation.BuildManager.GetVPathBuildResultFromCacheInternal(VirtualPath virtualPath, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
at System.Web.Compilation.BuildManager.GetObjectFactory(String virtualPath, Boolean throwIfNotFound)
at System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.FileExists(String virtualPath)
at System.Web.Mvc.BuildManagerViewEngine.FileExists(ControllerContext controllerContext, String virtualPath)
at System.Web.Mvc.VirtualPathProviderViewEngine.GetPathFromGeneralName(ControllerContext controllerContext, List`1 locations, String name, String controllerName, String areaName, String cacheKey, String[]& searchedLocations)
at System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext, String[] locations, String[] areaLocations, String locationsPropertyName, String name, String controllerName, String cacheKeyPrefix, Boolean useCache, String[]& searchedLocations)
at System.Web.Mvc.VirtualPathProviderViewEngine.FindView(ControllerContext controllerContext, String viewName, String masterName, Boolean useCache)
at System.Web.Mvc.ViewEngineCollection.<>c__DisplayClassc.<FindView>b__b(IViewEngine e)
at System.Web.Mvc.ViewEngineCollection.Find(Func`2 lookup, Boolean trackSearchedPaths)
at System.Web.Mvc.ViewEngineCollection.Find(Func`2 cacheLocator, Func`2 locator)
at System.Web.Mvc.ViewEngineCollection.FindView(ControllerContext controllerContext, String viewName, String masterName)
at Fablelane.WebApplication.Tests.Extensions.ControllerExtensions.RenderPartialToString(ControllerBase controller, String partialName, Object model, RouteData routeData) in ControllerExtensions.cs: line 28
at Fablelane.WebApplication.Tests.UseCases.InvokeView(Controller controller, ViewResult result) in UseCases.cs: line 104
at Fablelane.WebApplication.Tests.UseCases.CreateNewSchoolAsAdministrator() in UseCases.cs: line 226

そのエラーは、インスタンス化メソッドを使用したときです。

アプリケーション ホスト ソリューションを実行しようとすると、プロパティをシリアル化できないというシリアル化例外が発生して失敗します。

立ち往生しています - どうすればいいですか?

4

1 に答える 1

1

ビューはUIレイヤーにあり、UIレイヤーを単体テストするだけで、コントローラー/ビューが使用しているサービスレイヤーからすべてをモックアップします。

ユースケース(機能)が正しく実装されていることをテストチームがテストすると、ページを読み込めないかどうかが通知されるため、UIレイヤーには統合テストは必要ありません。

ビジネスロジックは通常、サービスレイヤーなどの別のレイヤーにあります。これは、サービス層とデータ層の間で統合テストが最も一般的に見られる場所です。

環境問題を回避しようとするのではなく、うまくいくものに固執してみませんか?UIレイヤーとユニットの単体テスト、およびサービスレイヤーの統合テスト。

さらに、自動ブラウザテストには、Seleniumなどを使用できます。

于 2012-04-07T04:43:20.503 に答える