dime-worldbank / Disease-Modelling-SSA

This repository contains the code for an agent-based model used for COVID-19 in Sub-Saharan Africa. The original code was written in Python by Aivin Solatorio and is since being developed in Java. Complimentary risk modelling has been conducted in R as an intermediate product and is also part of this repo
MIT License
6 stars 2 forks source link

unit testing #18

Open swise5 opened 1 year ago

swise5 commented 1 year ago

we have no unit testing suite, which is bad practice and makes merging the branches hazardous.

swise5 commented 1 year ago

Reviewing best practices (eg Baeldung and Unit Testing Principles, Practices, and Patterns by Khorikov, restructuring the project directory seems necessary. The question of how to ensure that the python scripts and the java project are made maximally accessible is unclear to me and I'm going to do a bit more reading about it.

swise5 commented 1 year ago

I've done a lot of refactoring, and it's probably worth us having a review session on how to rebase branches for merging purposes! In any case, the main branch now has a basic testing suite setup. I'll work on developing it further. For the time being, I am not making use of gradle - but in the future it would be helpful in terms of automatically jarring the code, etc.

RobertManningSmith commented 3 months ago

Go through and make these tests parameterized. e.g.

import static org.junit.Assert.assertTrue;

import java.util.Arrays;

import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized;

@RunWith(Parameterized.class) public class ParametrizedTest {

private final String text;
private final int number;

public ParametrizedTest(String text, int number) {
    this.text = text;
    this.number = number;
}

@Test
public void shouldContainNumber() {
    assertTrue(text.contains(String.valueOf(number)));
}

@Parameterized.Parameters
public static Iterable<Object[]> params() {
    return Arrays.asList(
            new Object[][]{
                    {"test string 1", 1},
                    {"test string 2", 2}
            }
    );
}

}