Skip to content

[SDK] Enable JUnit support for unit testing#5825

Merged
delchev merged 1 commit intomasterfrom
sdk-junit-initial
Apr 3, 2026
Merged

[SDK] Enable JUnit support for unit testing#5825
delchev merged 1 commit intomasterfrom
sdk-junit-initial

Conversation

@ThuF
Copy link
Copy Markdown
Contributor

@ThuF ThuF commented Apr 1, 2026

Fixes: #5824

@ThuF
Copy link
Copy Markdown
Contributor Author

ThuF commented Apr 1, 2026

Example Test Suite:

import { test, assertEquals, assertTrue, assertFalse, storeResults } from "@aerokit/sdk/junit";

// Example functions to test
function add(a: number, b: number): number {
    return a + b;
}

function multiply(a: number, b: number): number {
    return a * b;
}

function isPositive(num: number): boolean {
    return num > 0;
}

function validateEmail(email: string): boolean {
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    return emailRegex.test(email);
}

// Test Suites

// Suite: Basic Math Operations
test("add: should add two positive numbers", () => {
    const result = add(2, 3);
    assertEquals(5, result);
    console.log("✓ Test passed: add(2, 3) = 5");
});

test("add: should add negative numbers", () => {
    const result = add(-5, 3);
    assertEquals(-2, result);
    console.log("✓ Test passed: add(-5, 3) = -2");
});

test("add: should add zero", () => {
    const result = add(0, 5);
    assertEquals(5, result);
    console.log("✓ Test passed: add(0, 5) = 5");
});

test("multiply: should multiply two numbers", () => {
    const result = multiply(4, 5);
    assertEquals(20, result);
    console.log("✓ Test passed: multiply(4, 5) = 20");
});

test("multiply: should handle zero", () => {
    const result = multiply(5, 0);
    assertEquals(5, result);
    console.log("✓ Test passed: multiply(5, 0) = 0");
});

// Suite: Validation Functions
test("isPositive: should return true for positive numbers", () => {
    const result = isPositive(5);
    assertTrue(result);
    console.log("✓ Test passed: isPositive(5) = true");
});

test("isPositive: should return false for negative numbers", () => {
    const result = isPositive(-5);
    assertFalse(result);
    console.log("✓ Test passed: isPositive(-5) = false");
});

test("isPositive: should return false for zero", () => {
    const result = isPositive(0);
    assertFalse(result);
    console.log("✓ Test passed: isPositive(0) = false");
});

test("validateEmail: should accept valid email addresses", () => {
    const validEmails = [
        "user@example.com",
        "john.doe@company.co.uk",
        "test+tag@domain.org"
    ];

    validEmails.forEach(email => {
        const result = validateEmail(email);
        assertTrue(result, `Email ${email} should be valid`);
    });
    console.log("✓ Test passed: all valid emails accepted");
});

test("validateEmail: should reject invalid email addresses", () => {
    const invalidEmails = [
        "userexample.com",
        "user@example",
        "user @example.com",
        "user@.com"
    ];

    invalidEmails.forEach(email => {
        const result = validateEmail(email);
        assertFalse(result, `Email ${email} should be invalid`);
    });
    console.log("✓ Test passed: all invalid emails rejected");
});


storeResults();

Test run result:

Screenshot 2026-04-01 at 19 53 31

@delchev delchev merged commit c3bc525 into master Apr 3, 2026
19 of 20 checks passed
@delchev delchev deleted the sdk-junit-initial branch April 3, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SDK] Enable JUnit support for unit testing

2 participants