我需要爲我們的應用程序運行集成/迴歸測試套件,並且應用程序應該在一天的不同時間運行不同。我不能改變系統時間,因爲其他應用程序依賴於它我想嘲笑DateTime.Now爲此目的。但是,當我在主要方法中進行嘲諷時,拋出異常。當我在同一個應用程序的nunit測試中使用模擬時,它工作正常。 typemock只能在單元測試中使用嗎?無論如何,我可以運行嘲笑啓用解決方案嗎? 我通過TMockRunner.exe運行了解決方案,但也遇到同樣的問題。集成/迴歸測試套件中的TypeMock
謝謝!
我看到這個錯誤,當我運行使用特拉維斯提到 @Travis Illig公司的方法,用於包裝的代碼是:
class Program
{
static void Main(string[] args)
{
ExpectationsSetup();
ConsoleApplication2.Program.Main(args);
}
public static void ExpectationsSetup()
{
Isolate.WhenCalled(() => DateTime.Now).WillReturn(new DateTime(2010, 1, 2));
}
}
I see the following error:
Unhandled Exception: TypeMock.TypeMockException:
*** No method calls found in recording block. Please check:
* Are you trying to fake a field instead of a property?
* Are you are trying to fake an unsupported mscorlib type? See supported types
here: http://www.typemock.com/mscorlib-types
at gt.a(c0 A_0, Boolean A_1)
at bg.a(Boolean A_0)
at dt.b(Boolean A_0)
at i2.b(Boolean A_0)
at i2.a(Object A_0, Boolean A_1, Func`1 A_2, Action A_3, Action A_4, Action A
_5, Boolean A_6)
at i2.b(Object A_0)
at TypeMock.ArrangeActAssert.ExpectationEngine`1.a(TResult A_0)
at ConsoleApplication2Mock.Program.ExpectationsSetup() in C:\Users\shvenkat\D
ocuments\Visual Studio 2010\Projects\ConsoleApplication2\ConsoleApplication2Mock
\Program.cs:line 22
at ConsoleApplication2Mock.Program.Main(String[] args) in C:\Users\shvenkat\D
ocuments\Visual Studio 2010\Projects\ConsoleApplication2\ConsoleApplication2Mock
\Program.cs:line 14
任何幫助將不勝感激 謝謝!
謝謝特拉維斯!我用了類似的東西。 Mine是一個控制檯應用程序,並且我編寫了一個包裝控制檯應用程序,它執行期望設置等級。程序 static void Main(string [] args) ExpectationsSetup(); ConsoleApplication2.Program.Main(args); } public static void ExpectationsSetup() Isolate.WhenCalled(()=> DateTime.Now).WillReturn(new DateTime(2010,1,2)); } }。當我運行TMockRunner時,它會拋出異常。 – user1532105 2012-07-24 20:54:27
您應該更新您的問題以包含異常信息和包裝控制檯應用程序。很難排除故障或提供沒有所有信息的建議。 – 2012-07-24 22:00:09