Skip to content

Testing

Dmitri Nkosi Lezama edited this page Nov 17, 2024 · 14 revisions

Getting Started

Test Suite

Unit Tests

Performance Tests

Full coverage testing across the test suite measures the execution time of processes/methods and compares them against the performance limits defined in TestConstants (in ms).

This is achieved using an in-house microframework, ExecutionTimer, developed for precise performance analysis.

public class ExecutionTimer {
    public static <T> PerformanceTestResult testExecutionTime(Runnable task, long threshold, String testName) {
        long startTime = System.nanoTime();
        task.run();
        long endTime = System.nanoTime();
        long elapsedTime = (endTime - startTime) / 1_000_000;
        boolean success = elapsedTime <= threshold;
        System.out.println("Execution Time of " + testName + ": " + elapsedTime + " ms");
        return new PerformanceTestResult(testName, success, elapsedTime);
    }
}

Below is an example of a performance test for the GradingFacade's processSubmissions method (the GradingFacade is the system's main module, so this is a full-coverage system performance test):

public class FacadePerformanceTest {
    private static final PrintStream originalOut = System.out;

    @Test
    public void testFacadePerformance() throws Exception {
        System.setOut(new PrintStream(OutputStream.nullOutputStream()));
        Facade facade = new GradingFacade();
        PerformanceTestResult result = ExecutionTimer.testExecutionTime(
                () -> {
                    facade.processSubmissions("submissions.zip");
                },
                TestConstants.MAX_ALLOWABLE_THRESHOLD_MS,
                "Facade - Process Submissions");
        System.setOut(originalOut);
        assertTrue("Execution of processSubmissions took too long", result.isSuccess());
    }
}

Clone this wiki locally