.NET Coreç¨ã®ãã¹ãã©ã³ãã¼ãä½ã
[2017/02/18追è¨].NET Core SDK RC以éã§å®è£ æ¹æ³ãå¤ãã£ãã®ã§ãã®è¨äºãèªãã¹ãã§ã¯ããã¾ãã
ããã¯.NET Core Advent Calendar 4æ¥ç®ã®è¨äºã§ãã
.NET Coreã«å¯¾å¿ããã¦ããããã¹ã
ãã¦ãä¸ã®ä¸ã«ã¯ãã§ã«.NET Coreã«å¯¾å¿æ¸ã¿ã®ãã¹ãã£ã³ã°ãã¬ã¼ã ã¯ã¼ã¯ãããã¤ãåå¨ãã¾ãã
ããã§ã.NET Core CLIç¨ã®ã©ã³ãã¼ãæä¾ãã¦ããããã¸ã§ã¯ããã¿ã¦ã¿ã¾ãããã
- dotnet-test-nunit
- dotnet-test-xunit
- dotnet-test-mstest
- GitHubã§ãã¹ãã£ã³ã°ããã¦ããããã§ã¯ãªããããªã®ã§NuGetã®ãªã³ã¯ãã¯ã£ã¦ãã¾ã
- dotnet-test-mspec
- ã³ã³ã½ã¼ã«ã§ã¯åãã¾ããã2016/12/04æç¹ã§ã¯å¾è¿°ã®ãããã³ã«ã«å¯¾å¿ãã¦ãã¾ãã
- https://github.com/machine/machine.specifications/issues/303
主è¦ãã¬ã¼ã ã¯ã¼ã¯ã¯ãã§ã«previewãbetaçããªãªã¼ã¹ããã¦ããããã§ããã Visual Studioã«ã¹ã£ããï¼ï¼ï¼ã ã£ãMSTestã次ã®ãã¼ã¸ã§ã³ããNuGetã§åå¾ã§ããããã«ãªã£ãã®ãè¦æããããã¾ããã
ã¡ãªã¿ã«ãç§ãF#åããã¹ãã£ã³ã°ãã¬ã¼ã ã¯ã¼ã¯éçºã«æºãã£ã¦ããä¸äººã¨ãã¦runnerãä½ã£ã¦ããããã¾ãã
- dotnet-test-persimmon
- ããããä¸ååã§ããâ¦
ä»åã¯ãããã£ãã©ã³ãã¼ãå®è£ ããã«ã¯ã©ãããã°è¯ãããã¨ãã話ãéã«æ¸ãã¦ããã¾ãã
注æäºé
- çµå±å人ã¡ã¢ã¿ãããªå½¢ã«ãªã£ã¦ãã¾ã£ãã®ã§ãããã¥ããããâ¦
- 2016/12/04æç¹ã§ã®æ å ±ãªã®ã§ãæ£å¼ãªãªã¼ã¹ã®éã«ã¯ä»æ§ãå¤ãã£ã¦ãããããããªããã¨ã«æ³¨æãã¦ãã ããã
- ã³ã³ã½ã¼ã«ã®ã¿ã§åãã©ã³ãã¼ãä½ãå ´åã«ã¯ããã¾ã§ã®ç¥èã¯å¿
è¦ããã¾ãã
- éãè¨ãã°ãVisual Studioä¸ã§ãã¹ããåãããããªã対å¿å¿ é ã§ã
test communication protocol
.NET Core CLIã«ã¯test communication protocolã¨ãããã¹ãç¨ã®ãããã³ã«ãå®ãããã¦ãã¾ãã Visual Studio 2017以éã®ãã¹ãã¨ã¯ã¹ãã¼ã©ã¼ã¯ãã®ãããã³ã«ã使ã£ã¦.NET Coreãªãã¹ããå®è¡ãã¦ããããã§ããã
.NET Core CLI test communication protocol | Microsoft Docs
æ©æ¢°ç¿»è¨³ï¼ãããã¿ããã§ãã
.NET Core CLI テスト通信プロトコル | Microsoft Docs
å¿ è¦ã«ãªãç¥èã¯ãããèªãã°å ¨é¨æã«å ¥ãã®ã§ããããããèªãã ã ãã§å®è£ ã§ãããè¦å´ã¯ããªãâ¦ã
ã¨ããããã§ã以éã§ã¯å®è£ ã«å¿ è¦ãªãã®ãªã©ãããã¦ããã¾ãã
ããã±ã¼ã¸å
ããã±ã¼ã¸åã«é¢ãã¦ã¯project.json
æ代ã®è©±ãæ¸ãã®ã§ãç¶æ³æ¬¡ç¬¬ã§ã¯å½¹ã«ç«ããªããªãããããã¾ããã
ããã±ã¼ã¸åã¯dotnet-test-foo
ã®foo
é¨åã«ããã¸ã§ã¯ãåãã¤ãã¾ãã
ããã¯project.json
ã«"testRunner": "foo"
ã¨è¨è¿°ããã¨ã.NET CLIãä¾åé¢ä¿ã®ä¸ããdotnet-test-foo
ããã±ã¼ã¸ãæ¢ç´¢ããã¨ãã決ã¾ãäºãããããã§ãã
å
ã«ç´¹ä»ããããã¥ã¡ã³ãã®ã·ã¼ã±ã³ã¹å³å
ã§ã¯dotnet-test-runner
ã¨ãã表ç¾ããªããã¦ãã¾ãã
Microsoft.Extensions.Testing.Abstractions
ä½æããããã¸ã§ã¯ãã®ä¾åé¢ä¿ã«æ¬¡ã®ããã±ã¼ã¸ã追å ãã¾ãã
ãã®ããã±ã¼ã¸ã«ã¯Adapterãdotnet testã¨ã®éä¿¡ã§ä½¿ãåãã¤ã³ã¿ã¼ãã§ã¼ã¹ãå®ç¾©ããã¦ãã¾ãã
ã³ãã³ãã©ã¤ã³ãªãã·ã§ã³
ããã«åæãããªãã·ã§ã³ã¯Adapter, dotnet test, ã©ã³ãã¼ãé£æºããéã«å¿ è¦ã¨ãªãã¾ãã
Test discoveryï¼ãã¹ãæ¢ç´¢ï¼ã¨Test executionï¼ãã¹ãå®è¡ï¼ã«å ±éãããªãã·ã§ã³ã¨ããã§ãªããªãã·ã§ã³ãããã¾ãã
å ±é
designtimeãªãã·ã§ã³
design modeã示ããªãã·ã§ã³ã§ãã ãã®ãªãã·ã§ã³ãã¤ãã¦ããå ´åã¯ã³ã³ã½ã¼ã«å®è¡ã§ã¯ãªãã¨èããã»ããè¯ãã§ãããã
--designtime
portãªãã·ã§ã³
Adapterã¨ã©ã³ãã¼ããããã¯dotnet testã¨ã©ã³ãã¼éã§TCPéä¿¡ããããã®ãã¼ãçªå·ããªãã·ã§ã³ã§æ¸¡ããã¾ãã
--port ãã¼ãçªå·
ãã¹ã対象ã®ã¢ã»ã³ããªä¸è¦§
ãã¹ã対象ã®ã¢ã»ã³ããªã¯ãªãã·ã§ã³åãªãã®ã¹ãã¼ã¹åºåãã§æ¸¡ããã¾ãã
testAssembly1 testAssembly2
Test discoveryã§å¿ è¦ã«ãªããªãã·ã§ã³
listãªãã·ã§ã³
ãã¹ãã®ãªã¹ãã¢ãããè¦æ±ãããªãã·ã§ã³ã§ãã ãã®ãªãã·ã§ã³ã渡ãããå ´åãã©ã³ãã¼ã¯ãã¹ããå®è¡ããå¿ è¦ã¯ããã¾ããã
--list
Test executionã§å¿ è¦ã«ãªããªãã·ã§ã³
wait-commandãªãã·ã§ã³
å®è¡ãããã¹ãä¸è¦§ãåå¾ããããã«å¾ æ©ããå¿ è¦ããããã¨ã示ããªãã·ã§ã³ã§ãã
--wait-command
å®è£ é¢
æ¢ç´¢ãããã¹ãã®éä¿¡ããã¹ãçµæã®éä¿¡ã¯ITestDiscoverySinkãããã¯ITestExecutionSinkãå®è£ ããã¯ã©ã¹ã使ã£ã¦è¡ãã¾ãã ãã®2ã¤ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã¯Microsoft.Extensions.Testing.Abstractionsã«ããã¾ãã
ãã¼ããæå®ããã¦ããªãå ´å
Microsoft.Extensions.Testing.Abstractionsã«ç¨æããã¦ããStreamingTestDiscoverySinkã¨StreamingTestExecutionSinkã使ãã®ãæã£åãæ©ãã§ãã ããããã³ã³ã½ã¼ã«ä¸ã§å®è¡ãã¦ããã¯ããªã®ã§ãConsole.OpenStandardOutputã渡ãã°ããã¨æãã¾ãã
ãã¼ããæå®ããã¦ããå ´å
ç¬èªã«ITestDiscoverySink, ITestExecutionSinkãå®è£
ããã¯ã©ã¹ãç¨æãã¾ãâ¦â¦ã¨ãã£ã¦ãåºæ¬ã¯dotnet-test-nunitã®ãã¤ãã©ã¤ã»ã³ã¹ã¤ãã¦æã£ã¦æ¥ãã°ããã¨æãã¾ãã
NUnitã®ãã¤ã¯Socket, NetworkStream, BinaryWriterã使ã£ã¦éä¿¡ããããã«ãªã£ã¦ãã¾ãã
IPã¢ãã¬ã¹ã¯èªåã®PCãã¿ã¼ã²ãããªã®ã§IPAddress.Loopback
åºå®ã§å¤§ä¸å¤«ãªã¯ãã§ãã
Adapterãdotnet testã¨ã®éä¿¡ã¯Messageåã使ã£ã¦ããã¨ãããã¾ãã ããã¦ããã®Messageåã®Payloadã¯Newtonsoft.Jsonã使ã£ã¦ããã®ã§ãéä¿¡æã¯å¿ ç¶çã«Newtonsoft.Jsonã使ã£ã¦ã·ãªã¢ã©ã¤ãºãã¦ããéä¿¡ãã¾ãã
wait-commandãæå®ãããå ´å
ITestExecutionSink#SendWaitingCommand
ã§å¾ æ©ä¸ã§ãããã¨ãéä¿¡ããMessage#MessageType
ã«æå®ããæååã¯TestRunner.WaitingCommand
- BinaryReaderçã§éããã¦ããJSONãMessageã¨ãã¦ãã·ãªã¢ã©ã¤ãº
- ããã§éããã¦ãã
Message#Payload
ã®åã¯RunTestsMessage
ãªã®ã§ãmessage.Payload.ToObject<RunTestsMessage>().Tests
ãªã©ã¨ããã°å®è¡ãã¹ããã¹ãä¸è¦§ãåå¾ã§ãã
ããã§åå¾ã§ãããã¹ãä¸è¦§ã¯FullyQualifiedNameã¨ãªã£ã¦ãã¾ãã ãããç¨ãã¦ãã¹ãå®è¡åã«ãã£ã«ã¿ãªã³ã°ãã¦ãããã¨ã«ãªãã¾ãã
åããã©ããªã¼ã¨ããæ°æã¡ã«ãªãããããã¾ããããFullyQualifiedNameèªä½ãé·ãã£ãããããããã¹ãæ°ãå¤ãã£ãããã¦ã³ãã³ãã©ã¤ã³ã®ãµã¤ãºä¸éã容æã«è¶ ãã¦ãã¾ãã®ã§ä»æ¹ããªãã§ããã
ã¡ãã»ã¼ã¸ã®éä¿¡
Adapterãdotnet testã«æ å ±ãéä¿¡ããéã«ãMessageåã使ãã¾ãã
Messageã¯MessageType
ã¨ããstringã®ããããã£ãæã¡ã¾ãã
ã§ããã®MessageType
ã«æå®ããæååã¯æ±ºã¾ã£ã¦ããããã§ãããå®æ°ã¨ãã¦å®ç¾©ããã¦ããããã§ã¯ãªãã®ã§ã©ã³ãã¼å´ã§åèªå®ç¾©ãããããªãããã§ãã
ã·ãªã¢ã©ã¤ãº/ãã·ãªã¢ã©ã¤ãºã®ãã¨ãèãã¦stringãªã®ã¯ã¾ã許ããã¨ãã¦ãã©ããã¦å®æ°ãããã±ã¼ã¸å´ã§ç¨æããªãã£ãã®ã§ããããâ¦ã
TestFound
--list
ãªãã·ã§ã³ãæå®ããã¦ããæã«ãã¹ããçºè¦ããå ´åã¯ITestDiscoverySink#SendTestFound
ã使ã£ã¦ãã¹ããéä¿¡ãã¾ãã
Message#MessageType
ã«æå®ããæååã¯TestDiscovery.TestFound
ã§ãã
SendTestFound
ãå¾è¿°ããSendTestStarted
ã§ã¯Teståã®ãªãã¸ã§ã¯ããéä¿¡ããå¿
è¦ãããã®ã§ãããTest#Properties
ã®valueã«ã·ãªã¢ã©ã¤ãºã§ããªããããªå¤ãçªã£è¾¼ãã¨è½ã¡ãã®ã§æ°ãã¤ãã¾ãããã
TestStarted
--designtime
ãªãã·ã§ã³ãæå®ããã¦ããæããã¹ãå®è¡åã«ITestExecutionSink#SendTestStarted
ã使ã£ã¦ãã¹ãéå§ãéç¥ãã¾ãã
Message#MessageType
ã«æå®ããæååã¯TestExecution.TestStarted
ã§ãã
TestResult
--designtime
ãªãã·ã§ã³ãæå®ããã¦ããæããã¹ãå®è¡å¾ã«ITestExecutionSink#SendTestResult
ã使ã£ã¦ãã¹ãçµæãå ±åãã¾ãã
Message#MessageType
ã«æå®ããæååã¯TestExecution.TestResult
ã§ãã
ãªããF#ã®Asyncã使ã£ã¦Parallelã«å®è¡ãã¤ã¤ITestExecutionSink#SendTestResult
ãå¼ã³åºããã¨ããããã¹ãã2ã¤ä»¥ä¸å®è¡ãããã¨ããéã«SocketExceptionãæãããã¾ããã
åæçãªéç¥ã«ä¿®æ£ããããã®ä¾å¤ã¯çºçããªããªã£ãã®ã§ããããããã2016/12/04æç¹ã§ã¯ITestExecutionSink#SendTestResult
ãåæçã«å¼ã³åºãå¿
è¦ãããããããã¾ããï¼ã¤ãã¤ã確証ãæã¦ãªãã§ããâ¦ï¼ã
å¾çä»ã
--designtime
ãæå®ããã¦ããå ´åã¯ãITestDiscoverySink#SendTestCompleted
ãITestExecutionSink#SendTestComleted
ã使ã£ã¦å®äºãéç¥ãã¾ãã
Message#MessageType
ã«æå®ããæååã¯TestRunner.TestCompleted
ã§ãã
ã³ã³ã½ã¼ã«ã§å®è¡ãã¦ããå ´åã¯å¥éã³ã³ã½ã¼ã«ç¨ã®åºåãå®è£ ããããXMLã¬ãã¼ããã¡ã ã¤åãã¦ãããã°è¯ãã§ãããã
ãããã«
ãã¹ãã©ã³ãã¼ãå®è£ ããã«ã¯è²ã ã¨ãä½æ³ã«å¾ãå¿ è¦ããããã¨ãç解ã§ãããã¨æãã¾ãã
ããããVisual Studioã®ãã¹ãã¨ã¯ã¹ããã¼ã©ã¼ç¨æ¡å¼µãå®è£
ããããã¯æ ¼æ®µã«æ¥½ã«ãªã£ã¦ãã¾ãã
VSæ¡å¼µã§ã¯ããã¥ã¡ã³ããã»ã¨ãã©ãªããMicrosoft.VisualStudio.TestPlatform.ObjectModel
ã¨ããNuGetã«publishããã¦ããªãdllã¨æ ¼éããå¿
è¦ããã£ãããã§ãã
ä»åè¨åãã¦ããªãç¹ã¨ãã¦ã¯ãAppDomainã©ãããã®åé¡ãããã¾ãã ç¾è¡ã®.NET Coreã«ã¯AppDomainã«ç¸å½ããæ©è½ããªããããã©ãããã°è¯ãã®ãããããããªãã¨ããã®ãæ£ç´ãªã¨ããã§ãã xUnit.NETã§ã¯AppDomainãããç°å¢ã¨ãªãç°å¢ã§ifdefãé§ä½¿ãã¦ãã¿ããã§ãããæããã¦ãããæ£è§£ãªã®ãâ¦ï¼
ã¨ã¾ããé·ããªãã¾ããããå®è£ ãããã©ããã¯ã¨ãããèªåãã¡ã使ã£ã¦ãããããã³ã«ã®ä»æ§ãèªãã§ã¿ãã®ãä¸èãã¨æãã¾ãã