Beispiel #1
0
 public MutationSessionChoices()
 {
     SelectedOperators     = new List <IMutationOperator>();
     MutantsTestingOptions = new MutantsTestingOptions();
     TestAssemblies        = new List <TestNodeAssembly>();
     Filter = MutationFilter.AllowAll();
 }
 public VisualCodeTraverser(MutationFilter filter, VisualCodeVisitor visitor, CciModuleSource module)
 {
     _filter = filter;
     _visitor = visitor;
     _module = module;
     PreorderVisitor = visitor;
     _methodBodies = new Dictionary<IMethodBody, SourceMethodBody>();
 }
 public VisualCodeTraverser(MutationFilter filter, VisualCodeVisitor visitor, CciModuleSource module)
 {
     _filter         = filter;
     _visitor        = visitor;
     _module         = module;
     PreorderVisitor = visitor;
     _methodBodies   = new Dictionary <IMethodBody, SourceMethodBody>();
 }
        public void IntegrationTestingMiscUtilLight()
        {
            string filePath      = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath), @"..\..\..\..\Tests\SampleTestProjectsForTestDiscoveryAndExecution\SampleLogicNunit3Tests\bin\SampleLogic.dll"));
            string filePathTests = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath), @"..\..\..\..\Tests\SampleTestProjectsForTestDiscoveryAndExecution\SampleLogicNunit3Tests\bin\SampleLogicNunit3Tests.dll"));

            var cci     = new CciModuleSource(filePath);
            var choices = new MutationSessionChoices();
            var tt      = cci.Module.Module.GetAllTypes();
            //  var type = (NamedTypeDefinition)cci.Module.Module.GetAllTypes().Single(t => t.Name.Value == "Range");
            // var method = new MethodIdentifier(type.Methods.First(m => m.Name.Value == "Contains"));
            MethodIdentifier method = null;

            choices.SelectedOperators.Add(new IdentityOperator2());
            choices.Filter = method == null?MutationFilter.AllowAll() :
                                 new MutationFilter(
                                     new List <TypeIdentifier>(),
                                     method.InList());

            var options = new OptionsModel();
            var muexe   = new MutationExecutor(options, choices, null);
            var mucon   = new MutantsContainer(muexe, new OriginalCodebase(cci.InList()), new OptionsModel());
            var nodes   = mucon.InitMutantsForOperators(ProgressCounter.Inactive());

            Mutant mutant = nodes.Cast <CheckedNode>()
                            .SelectManyRecursive(n => n.Children ?? new NotifyingCollection <CheckedNode>())
                            .OfType <Mutant>().First();//.Take(4);

            var cciWhite = new CciModuleSource(filePath);
            var resu     = muexe.ExecuteMutation(mutant, cciWhite).Result;

            using (var file = File.OpenWrite(filePath))
            {
                resu.MutatedModules.WriteToStream(resu.MutatedModules.Modules.Single(), file, filePath);
            }

            var runContext = new NUnitTestsRunContext(
                options,
                _kernel.Get <IProcesses>(),
                _kernel.Get <CommonServices>(),
                new NUnitResultsParser(),
                TestProjects.NUnitConsolePath,
                filePathTests,
                new TestsSelector());

            var testResult = runContext.RunTests().Result;

            var count = testResult.ResultMethods
                        .GroupBy(t => t.State)
                        .ToDictionary(t => t.Key);
            var countStrings = count.Select(pair => pair.Key.ToString() + ": " + pair.Value.Count());

            _log.Info(string.Format("All test results: " + string.Join(" ", countStrings)));
            count[TestNodeState.Failure].Count().ShouldEqual(0);
        }
Beispiel #5
0
 public VisualCodeRewriter(IMetadataHost host, List <AstNode> capturedAstObjects,
                           List <AstNode> sharedAstObjects, MutationFilter filter,
                           IOperatorCodeRewriter rewriter, VisualCodeTraverser traverser)
     : base(host, rewriter)
 {
     _capturedASTObjects = capturedAstObjects;
     _sharedASTObjects   = sharedAstObjects;
     _filter             = filter;
     _rewriter           = rewriter;
     _traverser          = traverser;
     //    _rewriter.Parent = this;
     _formatter = new AstFormatter();
 }
Beispiel #6
0
        private IEnumerable <Mutant> SetupMutations(OriginalCodebase original,
                                                    List <FilePathAbsolute> paths, List <string> toMutate,
                                                    List <IMutationOperator> operators, MethodIdentifier method = null)
        {
            var options = new OptionsModel();

            options.OtherParams = "--debugfiles true";

            _kernel.Bind <IProjectClonesManager>().To <ProjectClonesManager>().InSingletonScope();
            _kernel.Bind <ProjectFilesClone>().ToSelf().AndFromFactory();
            _kernel.Bind <FilesManager>().ToSelf().InSingletonScope();
            _kernel.Bind <TestServiceManager>().ToSelf().InSingletonScope();
            _kernel.Bind <XUnitTestService>().ToSelf().InSingletonScope();
            _kernel.Bind <XUnitResultsParser>().ToSelf().InSingletonScope();
            _kernel.Bind <WhiteCache>().ToSelf().AndFromFactory();

            _kernel.Bind <INUnitWrapper>().To <NUnitWrapper>().InSingletonScope();
            _kernel.Bind <OriginalCodebase>().ToConstant(original);
            _kernel.Bind <ICodeDifferenceCreator>().To <CodeDifferenceCreator>().InSingletonScope();
            _kernel.Bind <ICodeVisualizer>().To <CodeVisualizer>().InSingletonScope();
            _kernel.Bind <IMutantsCache>().To <MutantsCache>().InSingletonScope();
            _kernel.Bind <NUnitTestsRunContext>().ToSelf().AndFromFactory();
            _kernel.Bind <XUnitTestsRunContext>().ToSelf().AndFromFactory();
            _kernel.Bind <OptionsModel>().ToConstant(options);
            _kernel.Bind <IMutationExecutor>().To <MutationExecutor>().InSingletonScope();
            _kernel.Bind <TestingMutant>().ToSelf().AndFromFactory();
            _kernel.Bind <TestLoader>().ToSelf().AndFromFactory();

            _kernel.BindMock <IHostEnviromentConnection>(mock =>
            {
                mock.Setup(_ => _.GetProjectAssemblyPaths()).Returns(paths);
                mock.Setup(_ => _.GetTempPath()).Returns(Path.GetTempPath());
            });

            _kernel.Get <ISettingsManager>()["NUnitConsoleDirPath"] = TestProjects.NUnitConsoleDirPath;
            _kernel.Get <ISettingsManager>()["XUnitConsoleDirPath"] = TestProjects.XUnitConsoleDirPath;

            _kernel.Bind <IWhiteSource>().ToConstant(new WhiteDummy(toMutate));

            var testsClone = _kernel.Get <IProjectClonesManager>().CreateClone("Tests");
            var testsTask  = _kernel.Get <TestsLoader>().LoadTests(testsClone.Assemblies.AsStrings().ToList());

            var strategy = new AllTestsSelectStrategy(testsTask);

            var choices = new MutationSessionChoices
            {
                Filter = method == null?MutationFilter.AllowAll() :
                             new MutationFilter(
                                 new List <TypeIdentifier>(),
                                 method.InList()),
                             SelectedOperators = operators,
                             TestAssemblies    = strategy.SelectTests(null).Result
            };

            _kernel.Bind <MutationSessionChoices>().ToConstant(choices);

            var exec      = _kernel.Get <MutationExecutor>();
            var container = new MutantsContainer(exec, original);
            IList <AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive());

            var mutants = assemblies.Cast <CheckedNode>()
                          .SelectManyRecursive(n => n.Children ?? new NotifyingCollection <CheckedNode>())
                          .OfType <Mutant>();//.Take(4);

            return(mutants);
        }
 public MutationTestingSession()
 {
     MutantsGrouped = new List <AssemblyNode>();
     Filter         = MutationFilter.AllowAll();
     Choices        = new MutationSessionChoices();
 }