UnitRun
ååï¼id:seiunsky:20061130:1164909243ï¼ã®ç¶ã
ãã®åã«
ããããNUnitèªä½è§¦ã£ã¦ããªãã£ãã®ã§NUnitã§ã®ããã¸ã§ã¯ãä½ææé ãã¾ã¨ãã¦ã¿ãã
ãã¹ãã¡ã½ããã®ä½æ
- ãã¹ãç¨ããã¸ã§ã¯ãããã¹ã対象ã½ãªã¥ã¼ã·ã§ã³ã«è¿½å
- ãã¹ãç¨ããã¸ã§ã¯ãã«nunit.frameworkã追å ï¼ãã¹ãç¨ããã¸ã§ã¯ãå³ã¯ãªãã¯âåç §ã®è¿½å â.NETã¿ãã«ããï¼
- ãã¹ãç¨ããã¸ã§ã¯ãã«ãã¹ã対象ããã¸ã§ã¯ãã®è¿½å ï¼ãã¹ãç¨ããã¸ã§ã¯ãå³ã¯ãªãã¯âåç §ã®è¿½å âããã¸ã§ã¯ãã¿ãã«ããï¼
- ãã¹ãã³ã¼ããæ¸ãï¼ãã¹ãã¡ã½ãããä½æããã«ã¯ NUnit.Frameworkãusingããï¼
ãã®ãããªæé ã§è¡ãã°ãã¹ãã³ã¼ããæ¸ããã¨ãã§ããã
以ä¸ã®ã³ã¼ã㯠sum.cs ã® sumã¯ã©ã¹ããã¹ãããã¨æã®ãã¹ãã¯ã©ã¹
using System; using System.Collections.Generic; using System.Text; using NUnit.Framework; using calc; namespace calcTest { /// <summary> /// sum.csãã¹ãç¨ã¯ã©ã¹ /// </summary> [TestFixture] public class sumTest { sum s; /// <summary> /// ãã¹ãã¯ã©ã¹ã§æåã®ä¸åç®ã«å®è¡ãããã¯ã©ã¹ã /// å¿ è¦ãªãã¼ã¿ã®åæåãªã©ããã¦ããã /// </summary> [TestFixtureSetUp] protected void sumInit() { s = new sum(); } /// <summary> /// å®éã®ãã¹ãã¯ã©ã¹ /// </summary> [Test] public void sumTest1() { Assert.AreEqual(30, s.sumCalc(10, 20)); } } }
æ°ãã¤ããã®ã¯ãã¹ãç¨ã¯ã©ã¹ã®å é ã«[TestFixture]å±æ§ãçããã³ãã¨ããã¹ãã¯ã©ã¹èªèº«ã public ãªå¯è¦æ§ã«ãªã£ã¦ããå¿ è¦ãããã¨ãããã¨ã
ãããResharper UnitRunã§å®è¡ãã¦ã¿ãã
ä¸è¨ã®ãããªãã¹ãã¡ã½ãããæ¸ãã¦ããã¨ç»é¢ã®è¡çªå·ããã¬ã¼ã¯ãã¤ã³ãã®è¡¨ç¤ºãããå ´æãããã«ãå¤ãªãã¼ã¯ã§åºç¾ãããã¨ã«æ°ãä»ãã¨æãã
ãã®ãã¼ã¯ãå·¦ã¯ãªãã¯ããRunãé¸æããã° Reshaper UnitRun ã®å®è¡ç»é¢ã表示ãããã¯ãã *1ã
ã§ãRunãå®è¡ããã¨ãã¹ãããã°ã©ã ãæµãã ãã ãã©ããã¬ã¼ã¯ãã¤ã³ããä»æãã¦ããDebugã§å®è¡ããã¨ãã¹ãããã°ã©ã ãã¹ãããå®è¡ã§ãã¬ã¼ã¹ãããã¨ãåºæ¥ãã
ãããããã«ãã¦ãResharperã®UIã¯è¯ããã
NUnitã®ããã©ã«ãã®ã¤ãã¯ã¡ãã£ã¨ããµãããVS2005ã¨ã¯å¥ã®ã¢ããªã«ãªã£ã¦ãã¾ãã®ã§ä½¿ãåæãæªããããã«ï¼ãããã¾ãè¦ãã¦ãªããã©ï¼TestDrivenã¯æåã»å¤±æã®è²ã¨ããåºãªãã¦ãããã·ã³ãã«ã ã£ãè¨æ¶ãããã
ããã«æ¯ã¹ãã¨ä½¿ãæ¹ãç°¡åã§ãè¦ãç®ãè¯ãããªããã¤VS2005ã¨é£åãã¦ããããã®ãã¼ã«ã¯ãã£ã»ã¢ã¼ã«ãè¯ããï¼
追è¨ï¼ã¢ããªã±ã¼ã·ã§ã³ã®å®è¡ã§ãã¾ãè¡ããªãå ´å
ã¹ã¿ã¼ãã¢ããããã¸ã§ã¯ãã®è¨å®ãæ£ãããªãå¯è½æ§ãããã
- ããã¸ã§ã¯ãã¨ã¯ã¹ããã¼ã©ä¸ã®ã¡ã¤ã³ã®ããã¸ã§ã¯ãä¸ã§å³ã¯ãªãã¯âã¹ã¿ã¼ãã¢ããããã¸ã§ã¯ãã«è¨å®ãé¸æ
- ãã¹ãç¨ããã¸ã§ã¯ããå³ã¯ãªãã¯âããããã£ãé¸æ
- åºåã®ç¨®é¡ãã¯ã©ã¹ã©ã¤ãã©ãªã«å¤æ´
ããã§å¤§ä¸å¤«ã ã¨æãã
追è¨ï¼ï¼NUnitã®ããã¥ã¢ã«
Exceptionãåããã¹ãã¯ã©ããã£ã¦ããã®ãï¼ããªã©ã®ä½¿ãæ¹ã«ã¤ãã¦ã¯ä»¥ä¸ãåèã«ãªãã¨æãã
http://www.objectclub.jp/community/XP-jp/xp_links/NUnitUsersGuidebookVer2.pdf
*1:ã¾ãã¯ã½ãªã¥ã¼ã·ã§ã³ã¨ã¯ã¹ããã¼ã©ã®ãã¹ãç¨ããã¸ã§ã¯ããå³ã¯ãªãã¯ãã¦ãè¯ã