<p>If you have the option, <a href="https://help.github.com/en/actions/automating-your-workflow-with-github-actions" rel="nofollow noreferrer">Github offers Actions</a> which allow you to run workflows on different events - one of them being push.</p>

<p>If Github is not an option, I would recommend creating a build where <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/build/ci-build-git?view=azure-devops&amp;tabs=yaml#exclude-or-include-tasks-for-builds-based-on-the-branch-being-built" rel="nofollow noreferrer">deployment of the artifacts only happens if the build is done on master</a>.</p>

<p>On your feature branches, on checkin, a build will happen which will pull the latest code, compile, and then run unit tests, security scanning, and code coverage (if applicable). Since this is a feature branch, the build ends there.</p>

<p>If it is on master, it then performs the steps to package/deploy the artifacts.</p>

<p>In Branches > Master > Branch Policies (in the ellipses menu), add a Build Validation.</p>

<p>I recommend marking it required.</p>

<p>If you aren't worried about merge conflicts causing a rebuild, you can make it expire immediately upon master changing (requiring a rebuild, which will fail on merge conflicts).  </p>

<p>If you are a large team where you might frequently step on one another, you can make it never expire and leave it up to the developer to fix manually before they are able to merge.</p>

CC BY-SA 4.0
2019-11-12T15:03:10.740Z
2019-11-12T15:03:10.740Z
Josh
<p>Is there a way in VSTS Azure for DevOps to implement unit test checking mechanism on pull request.</p>

<p>The condition is to only allow commits that change something in the unittest folder for example.</p>

<p>Notes:</p>

<ul>
<li><p>we are using GoCD as a CI/CD system so it's external building.</p></li>
<li><p>Git is internal hosted within VSTS.</p></li>
</ul>

CC BY-SA 4.0
2019-01-09T12:55:36.460Z
You can create a build with the unit tests and tun this build on the PR
Shayki Abramczyk
<git><azure-devops><cicd>
VSTS Azure for DevOps: Unit test checking mechanism on pull request
Daniel Johns
# VSTS Azure for DevOps: Unit test checking mechanism on pull request

(Asked by: username_0 on 2019-01-09)

Is there a way in VSTS Azure for DevOps to implement unit test checking mechanism on pull request.

The condition is to only allow commits that change something in the unittest folder for example.

Notes:

* we are using GoCD as a CI/CD system so it's external building.
* Git is internal hosted within VSTS.

**Tags:** git, azure-devops, cicd

> **Comments:**
> **username_1**: You can create a build with the unit tests and tun this build on the PR  

---

## 1 answers

### Answer by username_2 on 2019-11-12. Score: 1

If you have the option, [Github offers Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions) which allow you to run workflows on different events - one of them being push.

If Github is not an option, I would recommend creating a build where [deployment of the artifacts only happens if the build is done on master](https://docs.microsoft.com/en-us/azure/devops/pipelines/build/ci-build-git?view=azure-devops&tabs=yaml#exclude-or-include-tasks-for-builds-based-on-the-branch-being-built).

On your feature branches, on checkin, a build will happen which will pull the latest code, compile, and then run unit tests, security scanning, and code coverage (if applicable). Since this is a feature branch, the build ends there.

If it is on master, it then performs the steps to package/deploy the artifacts.

In Branches > Master > Branch Policies (in the ellipses menu), add a Build Validation.

I recommend marking it required.

If you aren't worried about merge conflicts causing a rebuild, you can make it expire immediately upon master changing (requiring a rebuild, which will fail on merge conflicts).

If you are a large team where you might frequently step on one another, you can make it never expire and leave it up to the developer to fix manually before they are able to merge.


---

