Skip to content
Rich Chiodo edited this page Jul 19, 2022 · 16 revisions

Types of tests

There are two types of tests in the jupyter extension

  • Unit
  • Integration

Unit tests are in files under the src\tests ending with the extension *.unit.test.ts Integration tests are in files under the 'src\tests' folder ending with the extension *.vscode.*.test.ts

Unit tests are generally written to test stateless complicated internal logic. We don't generally unit test everything. Integration tests are generally written for every use case that we might have. We attempt to have an integration test for every use case.

How to write a new unit test

Writing unit tests is pretty straightforward but there are some things to consider.

Unit test file

The general pattern is that any class that has a unit test, the unit test file is named the same but with a 'unit.test.ts' extension.

Unit test imports

We use mocha, sinon, chai, typemoq, ts-mockito and many others to run our tests. They generally follow a pattern like so:

suite(`My new unit test', () => {
    let foo: IFoo;

    setup(() => {
       // setup mocks
       foo = mock(FooClass); // Using ts-mockito to mock
       when(foo.bar).thenReturn(true);
    });

    test(`Test baz`, async () => {
       const baz = new Baz(foo);
       assert.ok(baz.bar, `Bar is not correct');
    });
});

Mostly we use ts-mockito to generate mock objects and sinon to stub out method calls but using typemoq is possible too.

How to write a new integration test

How to debug a unit test locally

How to debug an integration test locally

How to debug an integration test during CI

  • What a failure looks like
  • Data we capture
  • Looking at logs
  • Adding new log data
  • Looking at the test notebook
Clone this wiki locally