public void Ut <T>(bool loadFromIspacPackage = false) where T : BaseUnitTest { Type utClass = typeof(T); var customAttributes = utClass.GetCustomAttributes(false); UnitTestAttribute attribute = customAttributes.OfType <UnitTestAttribute>().Single(); string repository = attribute.Repository; string packageName = Path.GetFileName(attribute.PackageName); if (string.IsNullOrEmpty(packageName)) { throw new InvalidOperationException("Unit test class must have its PackageName set."); } var engine = EngineFactory.GetClassInstance <IUnitTestEngine>(); if (loadFromIspacPackage) { engine.LoadPackage(repository, Constants.PathToIspac, packageName); } else { string pathToTargetPackage = Path.Combine(Constants.PathToPackages, packageName); engine.LoadPackage(repository, pathToTargetPackage); } engine.LoadUnitTest(utClass); UnitTestResult result = engine.ExecuteUnitTest(utClass); }
public UnitTestHarnessControls(ControlBase parent) : base(parent) { Dock = Dock.Fill; DockBase dock = new DockBase(this); dock.Dock = Dock.Fill; m_List = new CollapsibleList(this); dock.LeftDock.TabControl.AddPage("Unit tests", m_List); dock.LeftDock.Width = 150; m_TextOutput = new ListBox(this); m_TextOutput.AlternateColor = false; dock.BottomDock.TabControl.AddPage("Output", m_TextOutput); dock.BottomDock.Height = 200; m_StatusBar = new StatusBar(this); m_StatusBar.Dock = Dock.Bottom; m_DebugCheck = new LabeledCheckBox(m_StatusBar); m_DebugCheck.Text = "Debug outlines"; m_DebugCheck.CheckChanged += DebugCheckChanged; m_IncScale = new Button(m_StatusBar); m_IncScale.HorizontalAlignment = HorizontalAlignment.Left; m_IncScale.VerticalAlignment = VerticalAlignment.Stretch; m_IncScale.Width = 30; m_IncScale.Margin = new Margin(0, 0, 8, 0); m_IncScale.TextPadding = new Padding(5, 0, 5, 0); m_IncScale.Text = "+"; m_IncScale.Clicked += (sender, arguments) => { m_UIScale.Value = Math.Min(m_UIScale.Value + 0.25f, 3.0f); }; m_UIScale = new TextBoxNumeric(m_StatusBar); m_UIScale.VerticalAlignment = VerticalAlignment.Stretch; m_UIScale.Width = 70; m_UIScale.Value = GetCanvas().Scale; m_UIScale.TextChanged += (sender, arguments) => { GetCanvas().Scale = m_UIScale.Value; }; m_DecScale = new Button(m_StatusBar); m_DecScale.HorizontalAlignment = HorizontalAlignment.Left; m_DecScale.VerticalAlignment = VerticalAlignment.Stretch; m_DecScale.Width = 30; m_DecScale.Margin = new Margin(4, 0, 0, 0); m_DecScale.TextPadding = new Padding(5, 0, 5, 0); m_DecScale.Text = "-"; m_DecScale.Clicked += (sender, arguments) => { m_UIScale.Value = Math.Max(m_UIScale.Value - 0.25f, 1.0f); }; m_UIScaleText = new Label(m_StatusBar); m_UIScaleText.VerticalAlignment = VerticalAlignment.Stretch; m_UIScaleText.Alignment = Alignment.Left | Alignment.CenterV; m_UIScaleText.Text = "Scale:"; m_Center = new DockLayout(dock); m_Center.Dock = Dock.Fill; List <Type> tests = typeof(UnitTestHarnessControls).Assembly.GetTypes().Where(t => t.IsDefined(typeof(UnitTestAttribute), false)).ToList(); tests.Sort((t1, t2) => { object[] a1s = t1.GetCustomAttributes(typeof(UnitTestAttribute), false); object[] a2s = t2.GetCustomAttributes(typeof(UnitTestAttribute), false); if (a1s.Length > 0 && a2s.Length > 0) { UnitTestAttribute a1 = a1s[0] as UnitTestAttribute; UnitTestAttribute a2 = a2s[0] as UnitTestAttribute; if (a1.Order == a2.Order) { if (a1.Category == a2.Category) { return(String.Compare(a1.Name != null ? a1.Name : t1.Name, a2.Name != null ? a2.Name : t2.Name, StringComparison.OrdinalIgnoreCase)); } else { return(String.Compare(a1.Category, a2.Category, StringComparison.OrdinalIgnoreCase)); } } return(a1.Order - a2.Order); } return(0); }); foreach (Type type in tests) { object[] attribs = type.GetCustomAttributes(typeof(UnitTestAttribute), false); if (attribs.Length > 0) { UnitTestAttribute attrib = attribs[0] as UnitTestAttribute; if (attrib != null) { CollapsibleCategory cat = m_List.FindChildByName(attrib.Category) as CollapsibleCategory; if (cat == null) { cat = m_List.Add(attrib.Category, attrib.Category); } GUnit test = Activator.CreateInstance(type, m_Center) as GUnit; RegisterUnitTest(attrib.Name != null ? attrib.Name : type.Name, cat, test); } } } m_StatusBar.SendToBack(); PrintText("Unit Test started!"); }