mardi 22 septembre 2015

My unit test does not show in Test Explorer

I am trying to set up a unit test in Typescript using tsUnit. I have created a very simple test just to make sure that I am doing things right. However, every time I click on Run All in Test Explorer it doesn't show me any results! It seems as though Visual Studios 2013 can't find any valid tests in my solution. Here is what I have in code:

/// <reference path="../../UnitTesting/UnitTesting/Scripts/tsUnit/tsUnit.ts" />

module CalculationsTests {
    export class SimpleMathTests extends tsUnit.TestClass {

        addTwoNumbersWith1And2Expect3() {
            var result = 1 + 2;

            this.areIdentical(3, result);
        }

        addTwoNumbersWith3And2Expect5() {
            var result = 3 + 6;

            this.areIdentical(4, result); // Deliberate error
        }
    }
}

window.onload = () => {
    // new instance of tsUnit - pass in modules that contain test classes
    var test = new tsUnit.Test(CalculationsTests);

    // Handle the results yourself...
    var result = test.run();

    var outcome = (result.errors.length === 0) ? 'Test Passed' : 'Test Failed';

    alert(JSON.stringify(outcome));
};

And in my main html file I have:

<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>TypeScript HTML App</title>
    <link rel="stylesheet" href="app.css" type="text/css" />
    <script src="/Scripts/tsUnit/tsUnit.js"></script>
    <script src="app.js"></script>
</head>
<body>
    <h1>TypeScript HTML App</h1>
    <h2>TS Unit Test</h2>
    <div id="content"></div>
</body>
</html>

Here's the result:

enter image description here

Can someone help me find out what I need to do in order to properly set up a unit test?

Aucun commentaire:

Enregistrer un commentaire