Skip to content

mrxbox98/Jast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

Jast

Maven Central FOSSA Status CodeFactor


<depedencies>
    <dependency>
        <groupId>me.mrxbox98.jast</groupId>
        <artifactId>jast</artifactId>
        <version>2.1.2</version>
    </dependency>
</depedencies>

A fast testing utility for Java based off of Jest for Javascript

import me.mrxbox98.jast.core.JastTestTests;

public class Test {
    public static void main(String[] args) {
        //Creates a new test
        JastTest jastTest = new JastTest();
        //Use reflection to get the method to test
        jastTest.setMethod(Test.class.getMethod("getString"));
        //Unlimited number of expected values
        jastTest.setExpected("tet","test");
        //Name of the test
        jastTest.setName("TestName");
        //Description of the test
        jastTest.setDescription("TestDescription");
        //The time the test should take in milliseconds
        jastTest.setTime(50);
        //Tests the method. Add a boolean param to determine if the results should be printed out
        jastTest.test();
    }

    public static String getString() {
        return "test";
    }
}

image

Chaining

Jast supports chaining so you can write an entire test in one line.

import me.mrxbox98.jast.core.JastTestTests;

public class Test {
    public static void main(String[] args) {
        //Creates a new test and sets both the method and expected values in one line
        JastTest jastTest = new JastTest().jastTest.setMethod(Test.class.getMethod("getString")).setExpected("tet","test");
    }

    public static String getString() {
        return "test";
    }
}

Mass Testing

You call add multiple tests to a mass test in order to tests multiple methods at a time.

import me.mrxbox98.jast.core.JastTestTests;
import me.mrxbox98.jast.core.MassTest;

public class Test {

    public static void main(String[] args)
    {
        try {
            MassTest byteMassTest = new MassTest();

            JastTest byteTest1 = new JastTest();
            byteTest1.setMethod(Test.class.getMethod("byteTest1"));
            byteTest1.setExpected((byte) 1);
            byteMassTest.add(byteTest1);

            JastTest byteTest2 = new JastTest();
            byteTest2.setMethod(Test.class.getMethod("byteTest2"));
            byteTest2.setExpected((byte) 2);
            byteMassTest.add(byteTest2);

            JastTest byteTest3 = new JastTest();
            byteTest3.setMethod(Test.class.getMethod("byteTest3"));
            byteTest3.setExpected();
            byteMassTest.add(byteTest3);



            byteMassTest.test(true);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }

    public static Byte byteTest1()
    {
        return 1;
    }

    public static Byte byteTest2()
    {
        return 2;
    }

    public static Byte byteTest3()
    {
        return null;
    }

}

image

Error Testing

import me.mrxbox98.jast.core.JastTestTests;
import me.mrxbox98.jast.core.MassTest;

public class ByteTest {
    public static void main(String[] args)
    {
        try {
            MassTest byteMassTest = new MassTest();

            JastTest byteTest1 = new JastTest();
            byteTest1.setMethod(ByteTest.class.getMethod("byteTest1"));
            byteTest1.setExpected((byte) 1);
            byteMassTest.add(byteTest1);

            JastTest byteTest2 = new JastTest();
            byteTest2.setMethod(ByteTest.class.getMethod("byteTest2"));
            byteTest2.setExpected((byte) 2);
            byteMassTest.add(byteTest2);

            JastTest byteTest3 = new JastTest();
            byteTest3.setMethod(ByteTest.class.getMethod("byteTest3"));
            byteTest3.setExpected();
            byteMassTest.add(byteTest3);

            JastTest byteTest4 = new JastTest();
            byteTest4.setMethod(ByteTest.class.getMethod("byteTest4"));
            byteTest4.setExpected(new ArrayIndexOutOfBoundsException());
            byteMassTest.add(byteTest4);

            JastTest byteTest5 = new JastTest();
            byteTest5.setMethod(ByteTest.class.getMethod("byteTest5"));
            byteTest5.setExpected(new IllegalArgumentException());
            byteMassTest.add(byteTest5);

            byteMassTest.test(true);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }

    public static Byte byteTest1()
    {
        return 1;
    }

    public static Byte byteTest2()
    {
        return 2;
    }

    public static Byte byteTest3()
    {
        return null;
    }

    public static Byte byteTest4()
    {
        throw new ArrayIndexOutOfBoundsException();
    }

    public static Byte byteTest5()
    {
        throw new IllegalArgumentException();
    }

}

image

License

FOSSA Status