Quantcast
Channel: Team Foundation Server - General forum
Viewing all articles
Browse latest Browse all 6687

Getting Code Coverage for Javascript Unit Tests under TFS Build server 2012

$
0
0

In our company, we are using VS 2012 and TFS 2012. The issue is we have a lot of Javascript unit tests that are using harness files *.html to get there results. We are using Chutzpah Test Adapter v2.3.0 to get their results (fail or pass) and the results are published perfectly under nightly builds under TFS build servers. The last version of Chutzpah Test Adapter v2.4.1 can get the code coverage for *.js files (using of course Blanket.js) only not *.html file which is a problem here because we have thousands of *.js unit tests that are using harness files.

One of our Devs has created a script that can get the code coverage for those harness files and export the results into a txt file or XML file, it's not a big deal. Now the issue that I want to publish those results under TFS build at nightly build using TFS

Publishing Coverage in TFS 2008 and Visual Studio 2010
http://mitchetter.wordpress.com/2011/02/26/publishing-coverage-in-tfs-2008-and-visual-studio-2010/

API. Depending on the code I found in the following link:

I came up with this code:

         

        public static void Initialization()
        {
            tfsUri = new Uri("http://OurTFSLinkAndPort");
            teamProject = "OurTeamProject";
            buildDefinition = "AkramVisualizationTests";

            buildUri = new Uri("OurTFSLinkAndPort/OurTeamProject");

            //var tfs = TeamFoundationServerFactory.GetServer(tfsUri);
            _tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);
            ibd = GetAllBuildDefinitionsFromTheTeamProject();

            IBuildDefinition bdef = null;
            foreach (IBuildDefinition tempbdef in ibd)
            {
                if (buildDefinition == tempbdef.Name)
                {
                    bdef = tempbdef;
                    break;
                }
            }

            builds = bdef.QueryBuilds();
            //var rr = builds.BuildServer.TeamProjectCollection.Uri.AbsoluteUri;
            IBuildDetail build = builds[builds.Length - 1];
            //var buildServer = (IBuildServer)_tfs.GetService(typeof(IBuildServer));
            //var build = buildServer.QueryBuildsByUri(new[] { buildUri }, new[] { "*" }, QueryOptions.All)[0];
            string temp = build.BuildNumber;

            IConfigurationSummary configSummary = InformationNodeConverters.GetConfigurationSummaries(build)[0];
            ICodeCoverageSummary coverageSummary = configSummary.AddCodeCoverageSummary();
            coverageSummary.BlocksCovered = 10;
            coverageSummary.BlocksNotCovered = 10;
            coverageSummary.LinesCovered = 20;
            coverageSummary.LinesNotCovered = 20;
            coverageSummary.LinesPartiallyCovered = 40;
            coverageSummary.Name = "Akram.js";
            coverageSummary.RunId = "123";
            coverageSummary.RunUser = "Akram";

            //workaround for MS assemblies not setting BuildInformationNode.Build
            //otherwise there's a NullReferenceException during Save()
            IBuildInformationNode coverageInfoNode = build.Information.GetNodesByType(InformationTypes.ConfigurationSummary)[0].Children.GetNodesByType(InformationTypes.CodeCoverageSummary)[0];
            PropertyInfo buildPropertyInfo = coverageInfoNode.GetType().GetProperty("Build", BindingFlags.Instance |  BindingFlags.DeclaredOnly | BindingFlags.NonPublic);
            buildPropertyInfo.SetValue(coverageInfoNode, build, null);
            coverageSummary.Save();
        }

        private static IBuildDefinition[] GetAllBuildDefinitionsFromTheTeamProject()
        {
            //buildServer = _tfs.GetService<IBuildServer>();
            buildServer = (IBuildServer)_tfs.GetService(typeof(IBuildServer));
            return buildServer.QueryBuildDefinitions(teamProject);
        }
Note: This: configSummary.AddCodeCoverageSummary(); has a warning that says it's [Deprecated] 
There is no exception thrown, no errors, but when I run this under my Demo solution under TFS build server, it gives me nothing at all, no results, no coverage file... etc.
Do you have any link how to fake code coverage results like in the following post:
Adding Fake Build Information in TFS 2010
http://geekswithblogs.net/jakob/archive/2012/03/30/adding-fake-build-information-in-tfs-2010.aspx
I would appreciate if you just direct me in the correct direction.

Note: By the way, I think there are too many Devs trying to get the same results here under TFS build servers, so, please Senior guys, try to help us all here.

Thanks in advance




Viewing all articles
Browse latest Browse all 6687

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>