jenkins running unit test of c++ code from visual studio on - c++

first of all I will show you how the program is structured:
I built the solution using jenkins as shown in the figure below
this is a cpp program. I do not know how to run unit test since there is no .exe file for unit test.
here is the .obj and .dll files in unit test folder
I know I should use MSbuild but I cannot find any thing that tells me how to run unittest on jenkins

Gold Rule #1 in devops
The steps should work in your localhost preferable on Linux and using the shell, before port it to Jenkins. If it don't work even on your localhost, Jenkins can't do anything.
Then if it works in your localhost (all the shells and installed tools required) , in jenkins you could use on of these approaches:
Jenkins shell script
Some Jenkins plugin to avoid the shell or scripts
Gold Rule #2 in devops
Use the shell, not programs with user interface , sometimes called IDEs. Devops flows for build, test, deploy are executed in the background and the 99.999% on Linux, not windows
c++ build
Reviewing, cmkake is used to build c++ applications. Also some others tools:
g++
make
cc
gcc
More details here: How to compile a c++ program in Linux?
Here a sample with g++
# compile
g++ ./foo/bar.cpp -o ./foo/bar
# this will generate an executable file ./foo/bar ready to be used
Since you have several files, you only need to append the files to the g++ according to:
https://stackoverflow.com/a/30064940/3957754
unit test
Depending of the classification (compiled/interpreted), execute a unit test is just to run a file:
java
mvn clean test
Searches all *Test.java files and if the files has the #Test annotation, the file is executed
nodejs
node /foo/bar/test.js
jest ...
mocha 'src/test/**/*.test.js'
Similar to java but with *.test.js files
As you can see, unit test is just to execute a file some times compiled previously or directly execution. So in your case, since c++ is a compiled language, to run your test , you only need
# compile
g++ ./UnitTest/UnitTest.cpp -o ./UnitTest/UnitTest
# run
./UnitTest/UnitTest
Visual Studio
This tool is for c#. If you read the previous paragraphs, you don't need complicated tools to build c++ projects.
Windows
You only need to choose one tool, install it on your windows, open the CMD shell or powershell and try the commands
g++
make
cc
gcc
If it works, go to your jenkins and use the shell step
References
https://www.stereolabs.com/docs/app-development/cpp/linux/
https://www.cyberciti.biz/faq/howto-compile-and-run-c-cplusplus-code-in-linux/
https://askubuntu.com/questions/61408/what-is-a-command-to-compile-and-run-c-programs
compile c++ through shell with jenkins
https://thoughts-on-coding.com/2019/03/27/introduction-into-build-automation-setup-with-jenkins-and-cmake/
https://www.cyberciti.biz/faq/howto-compile-and-run-c-cplusplus-code-in-linux/
How to compile a c++ program in Linux?
Making and compiling C++ projects with multiple files
https://www.baeldung.com/cs/compiled-vs-interpreted-languages

Related

Source environment variables before running cmake in VSCode

I am trying to build a large C++ framework in VSCode using CMakeTools and C/C++ Extensions in Visual Studio Code. I am browsing stackoverflow/github issues/any google suggestion and it looks like I am not the first person to encounter this, but I can not figure out for the life of me what am I doing wrong.
Here is the problem. I want to setup VSCode in a way to be able to build the framework (it is C++) right from VSCode using the built-in tools/extensions. Here is the process I was using up until now (in standard terminal in linux) and it also works in terminal run in VSCode:
cd /path-to-project-main-folder
source scripts/env.sh
cmake .
make -j 10
Now the problem is that when I set up VSCode, open the folder where the framework is, VSCode recognizes it is cmake project and gives me the opportunity to build it. Problem is that when I try to build it, it does not set up the environment first and therefore uses wrong cmake (not the sourced one but the default one build in server) and also wrong libraries and some of them are not even recognized.
The problem is in the first line:
source scripts/env.sh
where the environment variables are set and also PATHs to some libraries and programs. This line is not ran by VSCode before cmake and build.
Does anyone know a solution on how to configure CMakeTools extension to run:
source scripts/env.sh
line before running cmake and then make?
Thank you
I was looking into some solutions using tasks.json, settings.json files or creating my own kit. But no solution worked for me or I did not completely undestood the solution:
https://github.com/microsoft/vscode-cmake-tools/blob/HEAD/docs/tasks.md
https://github.com/microsoft/vscode-cmake-tools/issues/2243
https://github.com/microsoft/vscode-cmake-tools/pull/995
VSCode: Set environment variables via script
and man pages of CMakeTools, VSCode,...
VScode remote development: How can I run a build task to source environment variables before running the real build task? ---> but I use cmake
VSCode, how to source environment variable files like setup.bash?

C++ build automation in Jenkins (VS 2008 code)

We are trying to automate the C++ (VS 2008) code build using Jenkins. I have used Cmake with Unix makefiles as the generator and have completed generating the makefile but post that when i use make all from the build directory.
Now make all with "all" as that is the default target, there is no executable that gets generated and the Jenkins jobs shows as success but i cannot see the executable in any of the folders in the workspace.
I have tried to wipe out workspace and then executed still the build fails.
Is there something obvious that i have missed. Please help me..
Thanks
Shalini

Is there a way to get the information from MS unit test framework outside of the VS environment?

I created a test framework to test a sample application. This basically required creating a Solution for my sample application and then adding a Native Test Project, which can test the application.
The test project generates an .exe, but if I were to execute the .exe on it's own, it does nothing.
Is there a way to get information from the test programme so it can be used for other purposes outside of the VS environment?
Yes, you can run unit tests without VS2013.
Use Run automated tests from the command line using MSTest source to do so.
In general it says:
Open a Visual Studio command prompt.
Either change directory to your solution folder or, when you run the MSTest.exe program in step 3, specify a full or relative path to the metadata file or to the test container.
Run the MSTest.exe program.
I hope it will solve your issue.
It took a couple of days, but I've found that DeJaVo's answer is incorrect. Because I am running a Native Test Project, MSTest will not work with it. To run a Native Test from the command line, use VSTest.Console.

Unit Testing Windows 8 WIndows Runtime Component With TeamCity

I'm not a Windows 8 developer so excuse any stupid questions.
I have a Windows 8.1 application built in Visual Studio 2013 via a .sln file. This contains a number of projects: there is an application that relies on a library, this library (call it datalib) is built as a Windows Runtime Component (not a DLL);
there is also a test project which runs tests on 'datalib'
All of this works fine in VS2013, i.e. the tests execute.
I've been tasked with creating a TeamCity build for this so I've create a TeamCity build that builds against the sln file but I can't get the tests to execute (they're MSTest tests).
In my configuration I've added the test.dll (in the 'include assembly files list') but when I add this on it's own then I get a bunch of errors around references to types in the 'datalib'
The 'datalib' is built into datalib.winmd (I'm assuming this is the binary) so I thought that including this in the assembly list would fix my problem, but it doesn't.
I assume I'm missing something simple, what is it?
I'm now able to do this and it was a multi step process.
Firstly you don't load/test the winmd file directly you have to load the appx that's created by the test project 1; you can't use the MSTest runner that comes with TeamCity, instead you have to install the Visual Studio Test Runner plugin [2]; you have to run the build agent in an interactive process; and finally you have to install the root certificate that the application was signed with.
You reference the appx like you would a DLL
To install the build agent and have it run interactively it wasn't good enough to use the service and mark 'Interact with Desktop' you need to have full interaction so the agent has to be run from the desktop, as admin, at startup. To do this I had to create a scheduled task that run at startup and was given full privileges.
I installed the cert by running the ps1 file in the same directory as the appx file (Add-AppDevPackage.ps1) I'm sure this is overkill but it seemed like the easiest option at the time
[1] http://msdn.microsoft.com/en-us/library/hh691189.aspx
[2] https://confluence.jetbrains.com/display/TW/VSTest.Console+Runner

How to run C++ test on visual studio online

I have test cases that are executable (*.exe files). There is no user interface involved.
How do I use Team center /visual studio online to run these test cases on server.
For now, either on demand running or scheduled running will work for me.
(Currently I have no test case that runs on server. So you may mention the basic setup. )
I have written some test cases (they are exe files). I can run them locally line any other exe file.
My code is in C++.
My test cases are in C++.
You could run them as part of your build. Just configure a build in VSO for your solution, and then modify the msbuild project file to call your tests and send the output to the build folder so it gets uploaded as part of the drop. If you are using VS, you would get a better experience using the VS unit testing support (i.e., get results in VS): http://www.visualstudio.com/get-started/run-tests-with-builds-vs.