Run Tests in your build pipeline using Azure pipelines - VishalPatangay/My-devops-repo GitHub Wiki

https://docs.microsoft.com/en-gb/learn/modules/run-quality-tests-build-pipeline/4-add-unit-tests

A number of unit test frameworks are available for C# applications. Mara chooses NUnit because it's popular with the community and she's used it before.

Here's the unit test you're working with, along with Mara and Andy. [TestCase("Milky Way")] [TestCase("Andromeda")] [TestCase("Pinwheel")] [TestCase("NGC 1300")] [TestCase("Messier 82")] public void FetchOnlyRequestedGameRegion(string gameRegion) { const int PAGE = 0; // take the first page of results const int MAX_RESULTS = 10; // sample up to 10 results

// Form the query predicate.
// This expression selects all scores for the provided game region.
Expression<Func<Score, bool>> queryPredicate = score => (score.GameRegion == gameRegion);

// Fetch the scores.
Task<IEnumerable<Score>> scoresTask = _scoreRepository.GetItemsAsync(
    queryPredicate, // the predicate defined above
    score => 1, // we don't care about the order
    PAGE,
    MAX_RESULTS
);
IEnumerable<Score> scores = scoresTask.Result;

// Verify that each score's game region matches the provided game region.
Assert.That(scores, Is.All.Matches<Score>(score => score.GameRegion == gameRegion));

} This test queries the leaderboard for high scores and verifies that each result matches the provided game map.

In an NUnit test method, TestCase, provides inline data to use to test that method. Here, NUnit calls the FetchOnlyRequestedGameRegion unit test method like this: FetchOnlyRequestedGameRegion("Milky Way"); FetchOnlyRequestedGameRegion("Andromeda"); FetchOnlyRequestedGameRegion("Pinwheel"); FetchOnlyRequestedGameRegion("NGC 1300"); FetchOnlyRequestedGameRegion("Messier 82");

Notice the call to the Assert.That method at the end of the test. An assertion is a condition or statement that you declare to be true. If the condition turns out to be false, that could indicate a bug in your code. NUnit runs each test method using the inline data you specify and records the result as a passing or failing test.

Assert.That(scores, Is.All.Matches(score => score.GameRegion == gameRegion)); Assert that the game region of each returned score matches the provided game region.

Below link provides more details on how the test is run locally first and then update the yml file to include the unit tests and push the new build to git this triggers the new test case execution

https://docs.microsoft.com/en-gb/learn/modules/run-quality-tests-build-pipeline/4-add-unit-tests

Add a testing widget to dashboard

access dashboards> edit> new widget> "Test Results Trend." drag it on your dashboard. Configure the widget to select " Build pipeline" select your pipeline.

Code coverage https://docs.microsoft.com/en-gb/learn/modules/run-quality-tests-build-pipeline/6-perform-code-coverage

Summary: https://docs.microsoft.com/en-gb/learn/modules/run-quality-tests-build-pipeline/9-summary

⚠️ **GitHub.com Fallback** ⚠️