我正在爲Visual Studio 2010中的Silverlight 4進行單元測試。從Silverlight測試項目訪問項目資源時出錯
問題是我無法使用添加到測試項目中的資源。
在試運行時,我嘗試訪問這樣的種源:
[TestClass]
public class Class1
{
[TestMethod]
public void Test1()
{
// here I have an exception
Debug.WriteLine(Properties.Resources.String1);
,我得到一個異常:
System.TypeLoadException: Unable to load type "System.Runtime.Versioning.TargetFrameworkAttribute" from assembly "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
堆棧跟蹤
System.ModuleHandle.ResolveMethod(Int32 methodToken, RuntimeTypeHandle* typeInstArgs, Int32 typeInstCount, RuntimeTypeHandle* methodInstArgs, Int32 methodInstCount)
System.ModuleHandle.ResolveMethodHandle(Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
System.Reflection.CustomAttributeData..ctor(Module scope, CustomAttributeRecord caRecord)
System.Reflection.CustomAttributeData.GetCustomAttributes(Module module, Int32 tkTarget)
System.Reflection.CustomAttributeData.GetCustomAttributes(Assembly target)
System.Resources.ResourceManager.GetNeutralResourcesLanguage(Assembly a, UltimateResourceFallbackLocation& fallbackLocation)
System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
SilverlightClassLibraryTestProject1.Properties.Resources.get_String1() in D:\Work\Temp\SilverlightClassLibraryTestProject1\SilverlightClassLibraryTestProject1\Properties\Resources.Designer.cs: line 68
SilverlightClassLibraryTestProject1.Class1.Test1() in D:\Work\Temp\SilverlightClassLibraryTestProject1\SilverlightClassLibraryTestProject1\Class1.cs: line 13
我可以請參閱由Visual Studio創建的Silverlight測試項目包含對Microsoft.VisualStudio.QualityTools.UnitTestFramework的引用w這是一個.NET Framework 4.0程序集,而不是Silverlight。
我的問題是:現在可以在ResourceManager的幫助下使用Silverlight Test項目中的資源嗎?如果是,那麼應該做什麼?
下面是一個簡單test project
我已經重新上傳一個測試項目,其他位置。 –
我正在創建一個Silverlight類庫測試項目,並且引用了Microsoft.VisualStudio.QualityTools.UnitTestFramework程序集。 它有TestClassAttribute和TestMethodAttribute。如果您的Silverlight測試項目中沒有Microsoft.VisualStudio.QualityTools.UnitTestFramework,那麼我認爲您無法使用[TestClass]等。 –
請注意我已經添加了一個資源文件到項目中,問題是我在測試運行期間無法使用添加的資源 –