Issues with SonarQube Integration with VSTS with multiple MSbuild projects - build

In my build definition I have couple of Java & multiple MS build projects. Java projects are built using Ant. There are multiple ANT & MSbuild steps in build defination
I want to integrate my build with SonarQube. I referred to this link https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Extension+for+VSTS-TFS to add one begin analysis and one end analysis tasks,these tasks are added almost in the beginning & end of the build defination. Hence there are only 2 Sonar task & in between there are number of ms build and Ant tasks. When I run my build then I get some weird results on SonarQube. it seems like it scanned only part of codebase not the entire codebase.
I have following questions
Does SonarQube VSTS integration supports multiple MSbuild projects inside a same build definition. If Yes, can anyone please give pointers how to do that.
I have couple of Ant tasks as well. Is it supported by Sonar task? (its name says MSBuild task, is it applicable for Ant as well)?
Atul Sureka

Related

Static code analysis of .NET Core Unit test projects *.cs files with SonarQube

I have a Visual Studio .NET Core solution containing Unit Test projects. All the projects have a reference to the Microsoft.NET.Test.Sdk Nuget package is which according to my knowledge is a “must have” for unit tests execution.
I would like to perform static code analysis for unit test code (because it is also a code which is part of our deliverables). However, every time I am running Sonar Analysis as a part of Azure DevOps pipeline – I’m seeing “0” Lines of Code inside unit test *.cs files (and also other files inside unit test project) in the SonarQube report.
I have also found out interesting thing. In case I remove reference to the Microsoft.NET.Test.Sdk Nuget package – static code analysis is performed without any problems and code is visible for Sonar Qube scanner.
Also – the “dotnet build” command does not report any warnings for unit test projects when running on Azure DevOps build agent – even in case it should 😊.
My SonarQube Prepare task configuration pipeline file is very simple and looks like:
- task: SonarQubePrepare#4
displayName: Prepare SonarQube analysis
inputs:
SonarQube: 'SonarQube (XX)'
scannerMode: 'MSBuild'
projectKey: 'XXX-YYY'
projectName: 'XXX-YYY'
extraProperties: |
sonar.sources=src/**/*
Detailed dotnet build command run on Azure DevOps agent looks like:
/usr/bin/dotnet build /home/vsts/work/1/s/src/XXX.IntegrationTests/Tests/XXX.YYY.IntegrationTests.csproj -dl:CentralLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.181.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.181.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" --configuration Release
I am wondering what is so special about dotnet core projects with Microsoft.NET.Test.Sdk reference. Is there build process somehow different for them? Is there any way to “force” static code analysis for them?
Any help will be appreciated.
Ok. It occurs this is "by design" SonarQube behavior. Details and methods how to overwrite it may be found on: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects

TFS2015 - Determine impacted tests during vNext build

We've got several thousand unit tests that run in one of our projects. These currently take over ten minutes to run, and I'm trying to reduce this time.
One of the things I'm looking at is determining which tests are impacted by the latest code changes and only run those impacted tests. This seems to be a feature that TFS has, but all of the tutorials are from TFS2010 and the old XAML builds and not for the new vNext builds in TFS2015.
Does anyone have any experience in getting this to work?
Following this tutorial:
https://msdn.microsoft.com/en-us/library/ff576128(v=vs.100).aspx
I've defined a .testsettings file, and referenced it from a .runsettings file, and then in TFS2015 build I've set the .runsettings file as the Run Settings here:
But there doesn't seem to be any test impact files generated.
Answer from Microsoft:
Hi Steve,
Thanks for your post.
I tested it in my TFS 2015 vNext build and received the same result.
It seems there’s no the Analysis test impact = True/False option in
TFS 2015 vNext build Test task, this option is exist in XAML build
definition.
For this scenario, please submit it to User Voice site at:
http://visualstudio.uservoice.com/forums/121579-visual-studio,
Microsoft engineers will evaluate it seriously.
https://social.msdn.microsoft.com/Forums/en-US/610e304d-608e-49e9-8fcc-e65617828a6f/determine-impacted-tests-during-vnext-build?forum=tfsbuild

JaCoCo test coverage of ant based Netbean Module project

We have inherited a NetBeans Modules project (a.k.a. NetBeans Platform project) which builds using the NetBeans Ant tasks. We want to generate a code coverage report of the project to get an idea of what components are not being unit tested.
Generating a report is not part of the build process, it is simply something we want to do to understand the existing unit test coverage in the project.
We've decided to use JaCoCo to try and generate this. However the native support in NetBeans is for maven based projects. Unfortunately the TikiOne JaCoCoverage plugin currently does not support NetBeans Modules projects.
We are happy to just drive this via CLI to get an initial report. Does anyone have a success means of doing so under the given constraints?
Someone recently posted a related message to one of NetBeans mailing lists - https://netbeans.org/projects/platform/lists/dev/archive/2014-04/message/124
Short version: Cobertura plugin that does what you're looking for is not maintained now but you can build it and run it.
We have been successful in generating the report by doing the following:
Edited the project.properties file to run the JaCoCo agent when unit tests run. This is done by adding the following:
test.run.args=-javaagent:[yourpath/]jacocoagent.jar=destfile=[yourpath/]jacoco.exec
Use Netbeans to run the test task. This produces the jacoco.exec file.
Create a simple ant buildfile to generate reports from an .exec file (see this post)
Run the ant buildfile to generate the report.

Run xUnit tests from TFS2010

I'm trying to work out how to run xUnit tests from TFS 2010.
I found some articles on how to achieve that with the older version (http://jonnekats.wordpress.com/2009/05/07/integrate-xunit-tests-into-your-daily-team-build/, http://weblogs.asp.net/mehfuzh/archive/2009/08/25/configuring-team-build-using-xunit.aspx).
These approaches don't work anymore with TFS 2010 because builds are no longer MSBuild files but instead are Workflows with different tasks.
What I would like to achieve is something similar to what I've got on my dev machine:
- build everything
- run the .xunit project file
- check the results
All that I can see on the web are custom build steps which I can't/won't use because I'll have to configure them for each single unit test assembly and they'll probably get completely messed up in TFS.
Any input would be appreciated.
Why dont use "InvokeProcess" in TFS Build workflow and invoke xUnit command line interface with the necessary xUnit project files as parameters?
You can capture the output of the command line by setting InvokeProcess->stdout to write a build message.
Take a look at the xUnit work item Support VSTS Test Runner on codeplex. You can find there a VS2010 extension in Beta version.

How to set up a local test/build machine?

I am about to start a new personal project. It aims to be a pretty big one so I thought it would be a good idea to keep some sort of CVS. I have also read lot of interesting stuff about unit testing and I would like to include some system that automatically builds the project and runs a series of test after each check in.
The characteristics are:
Only one developer and one machine (just me and my computer!).
Include a CVS.
Include automated testing.
The software should be free (as in no-cost) and run under Linux.
It is going to be C++ and ANTLR based.
So far, I have set up SVN and Eclipse+CDT+ANTLR for development but I am pretty lost about the automated build+test setting. To write the tests I have been thinking in Boost.Test or UnitTest++.
So that's the source of my question. How should I set up my local test/build machine?
Links to valuable tutorials are more than welcome.
Thanks.
It seems that most open source continuous integration servers are built on java and does not support C++ "out-of-the-box". However there are some links you can start with (note that for running most open source continuous integration servers you need a java environment):
What continuous integration tool is best for a C++ project - some alternatives for continuous integration software
Continuous integration for C++ - some ideas for Hudson configuration
Using CruiseControl with C++ - some ideas and configurations for CruiseControl
Compiling C/C++ code with Ant - if you do use the "Makefile project" in CDT and do not want to use make as a build tool
I personally prefer Hudson because of its simply install (no need for application server just start with java -jar hudson.war) and easy to use and quite "clever" gui. Hudson can checkout your code from SVN (or CVS) and can run a shell script or Ant file as a build script. Maybe you have to spend a few days to set up a configuration with a proper build script but I think it worth the time.
The sort of automatic process you are looking at is called continuous integration. There is software to help you with this - a good example is JetBrains TeamCity. You will also hear of people using CruiseControl, Atlassian Bamboo and so on for this.
To take full advantage of this, you may also want to look at an automated build tool like Ant or Mavenl; your continuous integration build will then use this as its build runner.
A good starting point would be the Martin Fowler page on CI or the Wikipedia one.