我在 github 中查看了 Specflow 的代碼,發現了一個我無法理解的棘手問題。
https://github.com/SpecFlowOSS/SpecFlow/blob/master/TechTalk.SpecFlow/ScenarioContext.cs中的第 69 行
internal ScenarioContext(IObjectContainer scenarioContainer, ScenarioInfo scenarioInfo, ITestObjectResolver testObjectResolver)
https://github.com/SpecFlowOSS/SpecFlow/blob/master/Tests/TechTalk.SpecFlow.PluginTests/Infrastructure/WindsorPluginTests.cs中的第97~100行
var context = new ScenarioContext(
objectContainer.Object,
new ScenarioInfo("", "", Array.Empty<string>(), new OrderedDictionary()),
new WindsorTestObjectResolver());
TechTalk.SpecFlow.ScenarioContext 的建構式是內部的,這意味著它只能在 TechTalk.SpecFlow.dll 中訪問。為什么它仍然可以在 TechTalk.SpecFlow.PluginTests.Infrastructure.WindsorPluginTests 類中訪問?TechTalk.SpecFlow.PluginTests.Infrastructure.WindsorPluginTests 類位于 TechTalk.SpecFlow.PluginTests.dll 中。他們在不同的組裝。
uj5u.com熱心網友回復:
因為InternalsVisibleTo。這允許訪問從授權程式集呼叫的每個物件的內部型別、方法等。
在https://github.com/SpecFlowOSS/SpecFlow/blob/master/TechTalk.SpecFlow/AssemblyAttributes.cs中,程式集 TechTalk.SpecFlow 裝飾有其中一些屬性,將所有內部方法公開給列出的程式集:
- TechTalk.SpecFlow.RuntimeTests
- TechTalk.SpecFlow.PluginTests
這是一種非常常見且有用的技術,用于測驗任何人都不應訪問但需要測驗的方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/442184.html
上一篇:反序列化字典的Json陣列
