2016-05-18 5 views
1

私はa new projectを開始しました。これはC#クラスライブラリであり、ユーザが使用して拡張できる一連のウインドウが付属しています(Form)。Windows FormsでのC#テストはMono/Travisで失敗する

NUnitでWindowsにsome unit testsと書いて実行しました。私のテストのどれも、form.Show()を呼ぶ限り、行きません。テストはすべて、Windows上でTestDriven.NETと合格します。

トラヴィスは、Linux上でドッキングウィンドウコンテナの下で私のテストを実行すると、私は例外スタックを取得:

System.TypeInitializationException : The type initializer for 'System.Windows.Forms.WindowsFormsSynchronizationContext' threw an exception. ----> System.TypeInitializationException : The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ----> System.ArgumentNullException : Could not open display (X-Server required. Check your DISPLAY environment variable) Parameter name: Display at System.Windows.Forms.Control..ctor() <0x40965cf0 + 0x0005e> in <filename unknown>:0 at System.Windows.Forms.ScrollableControl..ctor() <0x409656f0 + 0x00017> in <filename unknown>:0 at System.Windows.Forms.ContainerControl..ctor() <0x40965520 + 0x0002d> in <filename unknown>:0 at System.Windows.Forms.Form..ctor() <0x40964bd0 + 0x000ef> in <filename unknown>:0 at Chrysalis.Core.Forms.ChrysalisForm..ctor() <0x40961790 + 0x00017> in <filename unknown>:0 at Chrysalis.Core.UnitTests.Forms.ChrysalisFormTests+TestChrysalisForm..ctor() <0x40961760 + 0x00014> in <filename unknown>:0 at (wrapper remoting-invoke-with-check) Chrysalis.Core.UnitTests.Forms.ChrysalisFormTests+TestChrysalisForm:.ctor() at Chrysalis.Core.UnitTests.Forms.ChrysalisFormTests.CancelButtonMovesWhenResizeEventFires() <0x409614f0 + 0x0003e> in <filename unknown>:0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x4090c360 + 0x000b7> in <filename unknown>:0 --TypeInitializationException at System.Windows.Forms.Theme.get_MenuAccessKeysUnderlined() <0x4096bcb0 + 0x00010> in <filename unknown>:0 at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined() <0x40967210 + 0x0001c> in <filename unknown>:0 at System.Windows.Forms.Control..ctor() <0x40965cf0 + 0x00274> in <filename unknown>:0 at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor() at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor() <0x40967100 + 0x00031> in <filename unknown>:0 --ArgumentNullException at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) <0x4096e400 + 0x00ec7> in <filename unknown>:0 at System.Windows.Forms.XplatUIX11..ctor() <0x4096c210 + 0x00231> in <filename unknown>:0 at System.Windows.Forms.XplatUIX11.GetInstance() <0x4096c000 + 0x00081> in <filename unknown>:0 at System.Windows.Forms.XplatUI..cctor() <0x4096bd20 + 0x00170> in <filename unknown>:0

それはヘッドレスだからビルドノードは明らかに、ディスプレイを持っていません。

この環境でテストを実行する方法はありますか?

答えて

1

私はこれをGitHub(Travis-CI repo)にクロス投稿し、AlexanderKöplingerから回答を得ました。

トラビスでは、GUIのバックエンドとしてxvfbを使用できます。その後、渡さ

before_script: 
    - "export DISPLAY=:99.0" 
    - "sh -e /etc/init.d/xvfb start" 
    - sleep 3 # give xvfb some time to start 

テスト:私はちょうど私の.travis.ymlファイルにこれを追加する必要がありました。

関連する問題