protected void InternalThreadStart() { //Note: We have a "wrapper" thread function thats always called. //This allows us much greater control than the normal System.Thread class. // 1. It allows us to call the function repeatedly (iterations) // 2. It allows parameters to be passed into the thread function // 3. It allows a return code from the thread function // 4. etc... //Iterate the specified number of times for(int i=0; i<Iterations; i++) { //call the user thread function try { Func(Param); } catch(Exception e) { //Note: If we don't handle this exception it doesn't get handled by the //main thread try-catch since its on a sperate thread. Instead of crashing the //URT - or requiring every thread function to catch any exception (there not expecting) //we will catch it and store the exception for later throw from the calling function TestLog.HandleException(e); _exception = e; //We should break out of this iteration break; } } }
// Initialization public void Init() { try { ; } catch (Exception e) { TestLog.HandleException(e); } }
public TestModule(string name, string desc) : base(name, desc, TestType.TestModule) { this.Guid = GetType().ToString(); //Population //DetermineChildren(); try { DetermineIncludes(); DetermineFilters(); } catch (Exception e) { //Don't completely block construction, otherwise it won't be able to be loaded from COM TestLog.HandleException(e); } }
public static bool Warning(object actual, object expected, string message, Exception inner) { //See if these are equal bool equal = InternalEquals(actual, expected); if (equal) { return(true); } try { throw new TestWarningException(message, actual, expected, inner); } catch (Exception e) { //Warning should continue - not halt test progress TestLog.HandleException(e); return(false); } }
public ITestItem CreateTest(String assembly, String type) { try { // this.Log = new LtmContext() as ITestLog; // this.Properties = new LtmContext() as ITestProperties; //Create an instance //Note: Assembly.CreateInstance returns null for type not found TestModule test = (TestModule)Assembly.LoadFrom(assembly).CreateInstance(type); if (test == null) { throw new TypeLoadException( String.Format("Unable to find type: '{0}' in assembly: '{1}'", type, assembly) ); } return(test); } catch (Exception e) { TestLog.HandleException(e); throw new TestFailedException(e.Message, null, null, e); } }
protected virtual TestResult HandleException(Exception e) { //Note: override this if your product has specilized exceptions (ie: nesting or collections) //that you need to recurse over of print out differently return(TestLog.HandleException(e)); }
public virtual List <TestVariation> EnumerateVariations(TestCase testcase, MethodInfo method) { int id = StartingId; List <object[]> rows = new List <object[]>(); List <MatrixColumnAttribute> matrixColumns = new List <MatrixColumnAttribute>(); object [] attributes = method.GetCustomAttributes(false); List <MatrixSkipConstraintAttribute> skipAttributes = new List <MatrixSkipConstraintAttribute>(); List <MatrixPriorityFilterAttribute> priorityAttributes = new List <MatrixPriorityFilterAttribute>(); foreach (MatrixColumnAttribute matrixColumn in attributes.OfType <MatrixColumnAttribute>()) { matrixColumns.Insert(0, matrixColumn); } foreach (MatrixSkipConstraintAttribute skipConstraint in attributes.OfType <MatrixSkipConstraintAttribute>()) { skipAttributes.Insert(0, skipConstraint); } foreach (MatrixPriorityFilterAttribute filter in attributes.OfType <MatrixPriorityFilterAttribute>()) { // TODO: why aren't we just doing add? or .ToList()? priorityAttributes.Insert(0, filter); } //Verify that no ParamOrderId's match IEnumerable <IGrouping <int, MatrixColumnAttribute> > grouping = matrixColumns.GroupBy <MatrixColumnAttribute, int>(mc => mc.ParamOrderId); foreach (IGrouping <int, MatrixColumnAttribute> group in grouping) { if (group.Key != -1) { if (group.Count() > 1) { throw new ArgumentException("For Matrix variation:" + this.PrefixName + " test method:" + method.Name + " Multiple MatrixColumnAttributes have the same ParamOrderId, this is invalid"); } } } //Sort it by ParamOrderId matrixColumns.Sort(CompareMatrixColumnParamId); foreach (MatrixColumnAttribute matrixColumn in matrixColumns) { rows = MultiplyMatrixRowsByColumn(matrixColumn, rows); } List <TestVariation> variations = new List <TestVariation>(); foreach (object[] matrixRow in rows) { //Every method that has a [Variation attribute] = a variation //Add this variation to our array TestFunc func = null; try { func = (TestFunc)Delegate.CreateDelegate(typeof(TestFunc), testcase, method); } catch (Exception e) { e = new TestFailedException("Variation: '" + method + "' doesn't match expected signature of 'void func()', unable to add that variation.", null, null, e); TestLog.HandleException(e); continue; } int i = 0; string description = null; //Calling from the list to reverse the attribute order so its in the order //as its in the code foreach (MatrixColumnAttribute matrixColumn in matrixColumns) { if (description == null) { description = this.PrefixName + " " + matrixColumn.Name + ":" + matrixRow[i].ToString(); } else { description = description + " " + matrixColumn.Name + ":" + matrixRow[i].ToString(); } i++; } if (!ShouldSkipVariation(testcase, matrixColumns, skipAttributes, matrixRow)) { TestVariation var = new TestVariation(description, func); var.Params = matrixRow; var.Id = id; var.Desc = description; var.Priority = VariationPriority(testcase, matrixColumns, priorityAttributes, matrixRow); variations.Add(var); id++; } } return(variations); }