Genesis

In the beginning, you created a folder.

>mkdir potassium

Then you made it a git repo.

>git init –bare

… wait, I don’t want to deal with github later. I’d rather create a new project on github ‘potassium’ then clone it.

>git clone git@github.com:myorg/potassium.git

>cd potassium

It feels home here. Let’s make it a maven project so we won’t need to worry about java library dependencies.

https://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project

>

mvn -B archetype:generate -DgroupId=com.myorg.potassium -DartifactId=potassium -DarchetypeArtifactId=maven-archetype-potassium -DarchetypeVersion=1.4

wait .. I made a mistake of creating the maven project ‘potassium’ under the folder I created as ‘potassium’ and I’m too lazy to fix the issue. I will take those out of the folder.

>mv potassium/* .
>rm -rf potassium

I test it by running a maven command.

>mvn clean install

Nice

Add TestNG dependency and create a base test class.

Google ‘maven testng’ to get
https://mvnrepository.com/artifact/org.testng/testng

Copied block goes to pom.xml but let’s open the project in IntelliJ first to handle this.

Open IntelliJ > Imort a new project > (select potassium folder) > maven

Any dependency will go under <dependencies> block per https://maven.apache.org/pom.html

IntelliJ’s .iml file is better staying local to individual developers. I’d leave it out of git repo. Creating .gitignore file to add *.iml pattern might be useful.

>vi .gitignore
>git add .gitignore
>git add pom.xml

Now we’re ready to add a Base class and BaseTest class.

public class Base
{
    private static Properties properties; // this should exist as a singleton
    Logger logger;

    Base() {
        try {
            properties = new Properties();
            InputStream stream = getClass().getClassLoader().getResourceAsStream("default.properties");
            properties.load(stream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger = Logger.getLogger(getClass().getName());
    }

    Properties getProperties() {
        return properties;
    }

    void info(String str) {
        logger.log(Level.INFO, str);
    }
}
public class BaseTest extends Base
{
BaseTest() {
super();
}

@Parameters({"env"})
@BeforeSuite(alwaysRun = true)
public void beforeSuite(@Optional("test-env") String envName) {
loadTestProperties(envName + ".properties");
}

void loadTestProperties(String envFile) {
try {
info("loading properties: " + envFile);
InputStream stream = getClass().getClassLoader().getResourceAsStream(envFile);
getProperties().load(stream);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public class PropertiesTest extends BaseTest {
    @Test
    public void defaultPropertiesTest()
    {
        Assert.assertEquals(getPropStr("frameworkName"), getPropStr("expectedName"));
    }
}

>mvn test