コード例 #1
0
        public void VerifyBuildFileOutsideSourcesShouldNotBeModified()
        {
            SetupMocks(_sourceDirectory);
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var buildFile2 = Path.Combine(Path.GetTempPath(), "build2.xml");

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

            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("summaryfile", _summaryFile);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);

            enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
            VerifyJacocoCoverageForAnt(numberOfTestNodes: 1, buildFilePath: _sampleBuildFilePath);
            VerifyJacocoCoverageForAnt(numberOfTestNodes: 1, buildFilePath: buildFile2, jacocoEnabled: false);
        }
コード例 #2
0
        public void EnableCodeCoverageForJacocoWithBuildFileNotInRepository()
        {
            var sourceDirectory = Path.Combine(Path.GetTempPath(), "sourceDirectory2");

            Directory.CreateDirectory(sourceDirectory);
            SetupMocks(sourceDirectory);
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();

            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("summaryfile", _summaryFile);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
            VerifyJacocoCoverageForAnt(numberOfTestNodes: 1, buildFilePath: _sampleBuildFilePath);
            VerifyJacocoReportForAnt();
            Directory.Delete(sourceDirectory, true);
            Assert.Equal(_warnings.Count, 0);
            Assert.Equal(_errors.Count, 0);
        }
コード例 #3
0
        public void MoreThanOneBuildFilesWithAnInvalidXmlDoesnotThrow()
        {
            SetupMocks(_sourceDirectory);
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var invalidXml = Path.Combine(_sourceDirectory, "invalid.xml");

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

            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("summaryfile", _summaryFile);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
            VerifyJacocoCoverageForAnt(numberOfTestNodes: 1, buildFilePath: Path.Combine(_sourceDirectory, "build.xml"));
            VerifyJacocoReportForAnt();
            Assert.Equal(_warnings.Count, 0);
            Assert.Equal(_errors.Count, 0);
        }
コード例 #4
0
        public void EnableCodeCoverageForAntDoesNotThrowWithNoTests()
        {
            SetupMocks(_sourceDirectory);
            LoadBuildFile(CodeCoverageTestConstants.BuildWithNoTestsXml);
            var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();

            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("summaryfile", _summaryFile);
            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, "Expected no exception. But got " + ex.GetType());
            }
            Assert.Equal(_warnings.Count, 0);
            Assert.Equal(_errors.Count, 0);
        }
コード例 #5
0
        public void EnableCodeCoverageForAntThrowsExceptionWithNoReportTask()
        {
            SetupMocks(_sourceDirectory);
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();

            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("summaryfile", _summaryFile);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            Assert.Throws <ArgumentException>(() => enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs)));
        }
コード例 #6
0
        public void EnableJacocoCodeCoverageForAntIfSourceDirectoryIsNotAvailable()
        {
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            SetupMocks("");
            var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();

            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("summaryfile", _summaryFile);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            Assert.Throws <InvalidOperationException>(() => enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs)));
        }
コード例 #7
0
        public void MoreThanOneBuildFilesWithAnInvalidMainBuildXmlThrowsException()
        {
            SetupMocks(_sourceDirectory);
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var invalidXml = Path.Combine(_sourceDirectory, "invalid.xml");

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

            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("summaryfile", _summaryFile);
            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)));
        }
コード例 #8
0
        public void EnableCodeCoverageForJacocoTestWithNo_includeExcludeFilters()
        {
            SetupMocks(_sourceDirectory);
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();

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

            ccInputs.Add("buildfile", _sampleBuildFilePath);
            ccInputs.Add("classfilesdirectories", _classDirectories);
            ccInputs.Add("sourcedirectories", _srcDirectory);
            ccInputs.Add("summaryfile", _summaryFile);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
            VerifyJacocoCoverageForAnt(numberOfTestNodes: 1, buildFilePath: _sampleBuildFilePath, includes: string.Empty, excludes: string.Empty);
            VerifyJacocoReportForAnt(string.Empty, string.Empty);
            Assert.Equal(_warnings.Count, 0);
            Assert.Equal(_errors.Count, 0);
        }
コード例 #9
0
        public void EnableCodeCoverageForJacocoTestWithFullClassNameFilters()
        {
            SetupMocks(_sourceDirectory);
            LoadBuildFile(CodeCoverageTestConstants.BuildXml);
            var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();

            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("summaryfile", _summaryFile);
            ccInputs.Add("reportdirectory", _reportDirectory);
            ccInputs.Add("ccreporttask", _cCReportTask);
            ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
            enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
            VerifyJacocoCoverageForAnt(numberOfTestNodes: 1, buildFilePath: _sampleBuildFilePath, includes: "app.com.SampleTest:app.*.UtilTest:app2*", excludes: "app.com.SampleTest:app.*.UtilTest:app3*");
            VerifyJacocoReportForAnt("**/app/com/SampleTest.class,**/app/*/UtilTest.class,**/app2*/**", "**/app/com/SampleTest.class,**/app/*/UtilTest.class,**/app3*/**");
            Assert.Equal(_warnings.Count, 0);
            Assert.Equal(_errors.Count, 0);
        }