My web app depends on an environment variable.
I wrote a unit test to ensure the environment variable is not null. The test passes on my local machine because, of course, I put the environment variable in my system variables. I had to restart Visual Studio for it to recognize the environment variable. But the test fails when it is built using CI in the cloud.
The TFS Build is scheduled to deploy it to a staging environment, and the environment variable is present in the staging environment as well as the production environment. If it is successful, it will deploy it to the staging environment, and then auto-swap with production. But it doesn't get far because the unit test fails. Is the unit test run in an environment different from the actual hosted website? If so, I must change my unit test strategy to not test environment variables. I may make an application status page to check such things then. But I wondered if anyone knew what was up on this.
The custom environment variable which you have in your personal machine must also be on the build controller. TFS Builds run on controller (Agents internally) and the unit tests run post build of the binary (Integral part of the Build before packaging)
Check if you can add the environment variable in the Build controller. You probably would need to reach the Build team and get that environment variable added in the Build server.
You also have a choice to "Pass the build if the unit test fails"
You can also categorize the unit test and set priorities and run only unit tests of certain priority; like priority 1 alone. You ca eliminate the case which is failing to be part of a unit test priority which you want to run.
Hope this helps!!
Related
I have downloaded and installed in a windows server 2016 a vs test agent, which was installed by a tool called Test Agent Configuration Tool. I then followed this guide to configure the agent to run tests that interact with desktop - I want to run CodedUI Tests for web projects from whithin my release pipeline.
This is the output from the Test Agent Configuration Tool
When I run my release pipeline I get this error during the test phase:
Error calling Initialization method for test class
Captura.PDV.Web.Test.CodedUI.CodedUITest1:
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestException: To
run tests that interact with the desktop, you must set up the test
agent to run as an interactive process. For more information, see "How
to: Set Up Your Test Agent to Run Tests That Interact with the
Desktop" (https://go.microsoft.com/fwlink/?LinkId=255012)
If you are
running the tests as part of your team build, you must also set up the
build agent to run as an interactive process. For more information,
see "How to: Configure and Run Scheduled Tests After Building Your
Application" (https://go.microsoft.com/fwlink/?LinkId=254735)
Here is my test task configuration:
Some notes and questions:
I can run the tests calling vstest.console.exe manually from within the server with success
My release pipeline runs on VSTS
I am not using Microsoft Test Manager - Is it really necessary?
Do I need to set up a test lab enviroment?
Do I need to have a controller for the agent?
I just want to run my tests in first place to see how it goes and then proceed to more advanced tests scenarios using MTM
You're mixed up between the old way of doing things and the new way.
You don't need to use MTM -- MTM is deprecated.
You don't need to set up a lab environment. Lab environments are deprecated.
You don't need special test controllers or agents.
All you should need to do in order to run UI tests is:
Set up a build/release agent that runs interactively.
Run the tests on that agent with the Visual Studio Test task with the "Test Mix Contains UI tests" check box checked.
That's it.
I'd also recommend against using Coded UI and instead use Selenium (or Appium for desktop applications); Microsoft is no longer investing in the Coded UI platform and recommends using Selenium as an alternative.
For creating a Build-Deploy-Test Workflow for my Wpf application, I ma using TFS Build definition and MTM to create Environment.
I am using following Steps:
I am Using LabDefaultTemplate.11.xaml in Build Definition
In the Lab Process Settings, I have given the required details as:
Environment: I have created an environment using MTM on the VM
in the environment I have added a Desktop Client(the same VM only) in the machines List
Please note that my Test Controller, agent, MTM all are on the VM only
Build: I have selected an existing build definition and it's working fine.
Deploy: I have specidfied command for application installation(running of msi file)
also, In the deploy section only, at the end I have specified a batch file where I am calling my CodedUI tests via command line(using VSTEST.CONSOLE.EXE)
Test: Not using it i.e. Not checked the "Run these Tests in Environment"
When I run this build definition, build creation, and installation are working fine but failes to run the codedui tests. Getting following error:
Error Message:
Error calling Initialization method for test class CodedUITestProject1.AISTest: Microsoft.VisualStudio.TestTools.UITest.Extension.UITestException: To run tests that interact with the desktop, you must set up the test agent to run as an interactive process. For more information, see "How to: Set Up Your Test Agent to Run Tests That Interact with the Desktop" (http://go.microsoft.com/fwlink/?LinkId=255012)
If you are running the tests as part of your team build, you must also set up the build agent to run as an interactive process. For more information, see "How to: Configure and Run Scheduled Tests After Building Your Application" (http://go.microsoft.com/fwlink/?LinkId=254735)
Stack Trace:
at Microsoft.VisualStudio.TestTools.UITesting.Playback.Initialize()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestExtensionExecution.BeforeTestInitialize(Object sender, BeforeTestInitializeEventArgs e)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecution.RaiseBeforeTestInitialize(BeforeTestInitializeEventArgs args)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.RunInitializeMethod()
Test Run Failed.
Also, I have made sure that test agent is configured as an interactive process.
Any Help would be highly appreciated.
The issue got resolved after setting the build controller also to run as a interactive process.
I wonder where I can use build environment variables in the job configuration.
For example:
At the "Source Code Management" I can use them.
At the "Trigger/call builds on other projects" sections "Predefined parameters" I can't use them, because they aren't resolved.
I don't find any scheme behind this. Is this depending on the plugin behind the build configuration section? (Git Plugin etc.)
I have one Job doing some stuff and generating a value within a groovy system script that is injected in the build environment.
def pa = new ParametersAction([
new StringParameterValue(key, value)
])
Thread.currentThread().executable.addAction(pa)
This value is needed as a build parameter of the called next build in the chain and used in this build job as the branch to be checked out.
But I don't know how to configure this.
You could make both those builds run on the same slave and and set the env variables on the slave in the first build. This env var then can be used by the downstream builds.
I would like some comments on the possibility or alternatives to the following workflow.
The players:
JimBob - Tester
APP_Test - Virtual machine configured with Lab, Build and Test agent. (shows testing and workflow capabilities active in the environment viewer)
Manual Test Environment - Environment consisting of one virtual machine "APP_Test"
Functional Tests - A test plan configured with the Test Environment for Manual runs being "Manual test Environment"
Build-Deploy - A TFS Build definition that restores a clean checkpoint and then deploys the latest version of the software to the "APP_Test" virtual machine
Build-Deploy-Test - A TFS Build definition that restores a clean checkpoint and then deploys the latest version of the software to the "APP_Test" virtual machine and then runs coded ui tests contained in the solution.
John - Tester/Dev
The scenario:
JimBob uses the TFS web interface to queue a new workflow build of the software ("Build-Deploy"). As part of the build the latest release of the software is deployed to the virtual machine "APP_Test". JimBob opens Microsoft Test Manager 2010 navigates to the Testing Centre, chooses the Test tab and highlights a Test from a previously defined Test Suite in the test plan "Functional Tests". When JimBob Runs the test the environment viewer opens viewing the "APP_Test" virtual machine. Jim performs the test and creates an action recording on the "APP_Test" virtual machine.
John then takes the action recording and creates a coded ui test, adds the test to the solution and when he queues the "Build-Deploy-Test" build it runs the coded ui test in the same environment that the original action recording was created in.
Questions:
I have created the environments, VM, Test plan and Test Suites outlined in the above scenario. What I can't seem to get working is that when a manual test is run it always runs the test on the Local machine not in a VM environment. This will not give me the ability to deploy so that my environment is always in a known state with no interference. I guess my question boils down to: Is it possible to use test management to create action recordings on virtual machines that belong to an environment? I have had success running tests on machines in environments but not making the initial recording. It seems to me that my testers should be able to always perform their tests (automated and manual) in a snapshotted known environment. What am I missing?
Maybe I didn't understand well, but since you want to perform recording you are talking about CodedUI I guess. I believe that the tester can record in his own workstation and perform any tweaks needed in the code and then deliver you an automated test case. Then you can run this automated test case in any virtual environment that satisfies your preconditions.
You cannot do action recording on a remote machine in the environment, see this link
Instead I installed MTM on the VM so I have a clean environment to build my tests in.
Im pretty new to CI so bear with me here. I have just setup an instance of Team City in on a local machine, and I can clearly see the benefits.
The one thing we do want understand is how we can managed the deployment aspect of CI. What we really want to achieve are two builds:
1) We check in to our source repository and the CI server notices the change and compiles the code, tests etc.
2) We manually trigger a build that compiles the code, copies the code to a remote server and update its IIS mappings.
Now the first build is pretty much wrapped up with TeamCity. But I assume that the deployment aspect of this is going to involve some scripting (Nant, MsBuild, Rake etc) is this correct?
If this is the case, I can see that transferring files from the build machine to a remote server will be ok, but will we be able to update IIS mappings without being on the same network? For that matter where is THE correct place to deploy a CI server, should is live on the same network as the apps we deploy?
Finally, we have been (rather unorthadoxily) using IronRuby to run rake scripts as our build runner. This is simply because we like Rake, but if we were to look at Nant/Msbuild do they have any baked in tasks that would simplify what we are trying to achieve?
Cheers, Chris.
We use MSBuild exclusively, just a choice. I am sure Nant and the others do things just as well. We only publish to a dev environment (for dev testing) and a stage environment (Where QA actually tests). I would not suggest that you put the production system push on this as the temptation to force builds might be too great for some people.
We use some of the MSBuild Community Tasks