Пример #1
0
        public void EnableCodeCoverageForAntDoesNotThrowExceptionWithNoTests()
        {
            SetupMocks();
            LoadBuildFile(CodeCoverageTestConstants.BuildWithNoTestsXml);
            var enableCodeCoverage = new CodeCoverageEnablerForCoberturaAnt();

            enableCodeCoverage.Initialize(_hc);
            var ccInputs = new Dictionary <string, string>();

            ccInputs.Add("buildfile", _sampleBuildFilePath);
            ccInputs.Add("classfilesdirectories", _classDirectories);
            ccInputs.Add("classfilter", _classFilter);
            ccInputs.Add("sourcedirectories", _srcDirectory);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            try
            {
                enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
            }
            catch (Exception ex)
            {
                Assert.True(false, string.Format("No exception was expected! The exception message: {0}", ex.Message));
            }
        }
Пример #2
0
        public void MultipleBuildFilesWithOneOfThemBeingInvalidShouldNotThrow()
        {
            SetupMocks();
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var invalidXml = Path.Combine(_sourceDirectory, "invalid.xml");

            File.WriteAllText(invalidXml, "invalidXmlData");
            var enableCodeCoverage = new CodeCoverageEnablerForCoberturaAnt();

            enableCodeCoverage.Initialize(_hc);
            var ccInputs = new Dictionary <string, string>();

            ccInputs.Add("buildfile", _sampleBuildFilePath);
            ccInputs.Add("classfilesdirectories", _classDirectories);
            ccInputs.Add("classfilter", _classFilter);
            ccInputs.Add("sourcedirectories", _srcDirectory);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
            VerifyCoberturaCoverageForAnt(numberOfTestNodes: 1, buildFilePath: Path.Combine(_sourceDirectory, "build.xml"));
            VerifyCoberturaReport();
            Assert.Equal(_warnings.Count, 0);
            Assert.Equal(_errors.Count, 0);
        }
        public void MoreThanOneBuildFilesExistInBuildSources()
        {
            SetupMocks();

            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var buildFile2 = Path.Combine(_sourceDirectory, "build2.xml");

            File.WriteAllText(buildFile2, CodeCoverageTestConstants.BuildXml);
            var enableCodeCoverage = new CodeCoverageEnablerForCoberturaAnt();

            enableCodeCoverage.Initialize(_hc);
            var ccInputs = new Dictionary <string, string>();

            ccInputs.Add("buildfile", _sampleBuildFilePath);
            ccInputs.Add("classfilesdirectories", _classDirectories);
            ccInputs.Add("classfilter", _classFilter);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("sourcedirectories", _srcDirectory);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);

            enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
            VerifyCoberturaCoverageForAnt(numberOfTestNodes: 1, buildFilePath: _sampleBuildFilePath);
            VerifyCoberturaCoverageForAnt(numberOfTestNodes: 1, buildFilePath: buildFile2);
        }
Пример #4
0
        public void EnableCodeCoverageForAntThrowsExceptionWithNoBuildFile()
        {
            SetupMocks();
            var enableCodeCoverage = new CodeCoverageEnablerForCoberturaAnt();

            enableCodeCoverage.Initialize(_hc);
            var ccInputs = new Dictionary <string, string>();

            ccInputs.Add("classfilesdirectories", _classDirectories);
            ccInputs.Add("classfilter", _classFilter);
            ccInputs.Add("sourcedirectories", _srcDirectory);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            Assert.Throws <ArgumentException>(() => enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs)));
        }
Пример #5
0
        public void EnableCodeCoverageForAntThrowsExceptionWithNonExistingBuildFile()
        {
            SetupMocks();
            var buildFile = "invalid.xml";

            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var enableCodeCoverage = new CodeCoverageEnablerForCoberturaAnt();

            enableCodeCoverage.Initialize(_hc);
            var ccInputs = new Dictionary <string, string>();

            ccInputs.Add("buildfile", buildFile);
            ccInputs.Add("classfilesdirectories", _classDirectories);
            ccInputs.Add("classfilter", _classFilter);
            ccInputs.Add("sourcedirectories", _srcDirectory);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            Assert.Throws <FileNotFoundException>(() => enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs)));
        }
Пример #6
0
        public void MultipleBuildFilesWithMAinBuildFileBeingInvalidShouldThrow()
        {
            SetupMocks();
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var invalidXml = Path.Combine(_sourceDirectory, "invalid.xml");

            File.WriteAllText(invalidXml, "invalidXmlData");
            var enableCodeCoverage = new CodeCoverageEnablerForCoberturaAnt();

            enableCodeCoverage.Initialize(_hc);
            var ccInputs = new Dictionary <string, string>();

            ccInputs.Add("buildfile", invalidXml);
            ccInputs.Add("classfilesdirectories", _classDirectories);
            ccInputs.Add("classfilter", _classFilter);
            ccInputs.Add("sourcedirectories", _srcDirectory);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            Assert.Throws <XmlException>(() => enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs)));
        }
Пример #7
0
        public void EnableCodeCoverageForAntCoberturaTestWithNoIncludeExcludeFilters()
        {
            SetupMocks();
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var enableCodeCoverage = new CodeCoverageEnablerForCoberturaAnt();

            enableCodeCoverage.Initialize(_hc);
            var ccInputs = new Dictionary <string, string>();

            ccInputs.Add("buildfile", _sampleBuildFilePath);
            ccInputs.Add("classfilesdirectories", _classDirectories);
            ccInputs.Add("sourcedirectories", _srcDirectory);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
            VerifyCoberturaCoverageForAnt(numberOfTestNodes: 1, buildFilePath: _sampleBuildFilePath, includes: string.Empty, excludes: string.Empty);
            VerifyCoberturaReport();
            Assert.Equal(_warnings.Count, 0);
            Assert.Equal(_errors.Count, 0);
        }
Пример #8
0
        public void EnableCodeCoverageForAntCoberturaTestWithFullClassNameFilters()
        {
            SetupMocks();
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var enableCodeCoverage = new CodeCoverageEnablerForCoberturaAnt();

            enableCodeCoverage.Initialize(_hc);
            var ccInputs = new Dictionary <string, string>();

            ccInputs.Add("buildfile", _sampleBuildFilePath);
            ccInputs.Add("classfilesdirectories", _classDirectories);
            ccInputs.Add("classfilter", "+:app.com.SampleTest,+:app.*.UtilTest,+:app2*,-:app.com.SampleTest,-:app.*.UtilTest,-:app3*");
            ccInputs.Add("sourcedirectories", _srcDirectory);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
            VerifyCoberturaCoverageForAnt(numberOfTestNodes: 1, buildFilePath: _sampleBuildFilePath, includes: "**/app/com/SampleTest.class,**/app/*/UtilTest.class,**/app2*/**", excludes: "**/app/com/SampleTest.class,**/app/*/UtilTest.class,**/app3*/**");
            VerifyCoberturaReport();
            Assert.Equal(_warnings.Count, 0);
            Assert.Equal(_errors.Count, 0);
        }