• Test function for writing test cases with conditional execution based on enable control. Provides test context, automatic logging, and supports both synchronous and asynchronous operations. Test execution is controlled by the testEnableControl configuration.

    Parameters

    • name: string

      The name of the test case

    • fn: () => void | Promise<void>

      The test function to execute (can be sync or async)

    Returns void

    // Basic synchronous test case
    test('should validate CAN message format', () => {
    const canMsg = { id: 0x123, data: [0x01, 0x02] };
    assert.equal(canMsg.id, 0x123);
    assert.equal(canMsg.data.length, 2);
    });

    // Asynchronous test case for UDS communication
    test('should perform UDS diagnostic session', async () => {
    await uds.service(0x10, 0x01); // DiagnosticSessionControl
    const response = await uds.getResponse();
    assert.equal(response[0], 0x50); // Positive response
    });

    // Test with CAN bus operations
    test('should send and receive CAN messages', async () => {
    await can.send({ id: 0x7E0, data: [0x02, 0x10, 0x01] });
    const msg = await can.recv(1000);
    assert.notEqual(msg, null);
    });

    // Skip a test case when feature is not ready
    test.skip('LIN transport protocol test', () => {
    // Test code that will be skipped
    lin.sendMessage(0x3C, [0x01, 0x02, 0x03]);
    });

Methods

Methods

  • Parameters

    • name: string
    • fn: () => void | Promise<void>

    Returns void