Table Driven Test in Java using Junit4 I was creating some solving algorithm and write test for it. this is the tests : 

    @Test
    public void test1(){
        boolean expected = true;
        int n = 7;
        DigitIncreasing digitIncreasing = new DigitIncreasing();
        assertEquals(expected,digitIncreasing.isDigitIncreasing(n));
    }

    @Test
    public void test2(){
        boolean expected = true;
        int n =36;
        DigitIncreasing digitIncreasing = new DigitIncreasing();
        assertEquals(expected,digitIncreasing.isDigitIncreasing(n));
    }

    @Test
    public void test3(){
        boolean expected = true;
        int n = 984;
        DigitIncreasing digitIncreasing = new DigitIncreasing();
        assertEquals(expected,digitIncreasing.isDigitIncreasing(n));
    }

    @Test
    public void test4(){
        boolean expected = true;
        int n = 7404;
        DigitIncreasing digitIncreasing = new DigitIncreasing();
        assertEquals(expected,digitIncreasing.isDigitIncreasing(n));
    }

    @Test
    public void test5(){
        boolean expected = false;
        int n = 37;
        DigitIncreasing digitIncreasing = new DigitIncreasing();
        assertEquals(expected,digitIncreasing.isDigitIncreasing(n));
    }


So from here I got some idea to write the test using Table driven approach like this : 

     public class testObject {
        private int input;
        private boolean expected;

        public testObject(int input, boolean expected) {
            this.input = input;
            this.expected = expected;
        }

        public int getInput() {
            return input;
        }

        public boolean isExpected() {
            return expected;
        }
    }

    public void DigitIncreasing(int input, boolean expected){
        try{
            DigitIncreasing digitIncreasing = new DigitIncreasing();
            assertEquals(expected,digitIncreasing.isDigitIncreasing(input));
        }catch (AssertionError ex){
            System.out.println("input = "+input);
            System.out.println("expected = "+expected);
            ex.printStackTrace();
        }

    }

    @Test
    public void testTable(){
        testObject[] testObjects = new testObject[]{
                new testObject(7,true),
                new testObject(36,true),
                new testObject(984,true),
                new testObject(7404,true),
                new testObject(37,false),
       };

        for (testObject test : testObjects){
            DigitIncreasing(test.getInput(),test.isExpected());
        }
    }


Using Table Driven test makes me easily add another test case. any better approach or idea? since I'm adding the catch exception to get failed test.

You can find source code here.
JUnit 4 has a Parameterized test runner that does most of the work for you. For your tests, it would look like:

import maharishi.DigitIncreasing;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collection;

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

@RunWith(Parameterized.class)
public class DigitIncreasingTest {

    @Parameters(name = "Test {index}: isDigitIncreasing({0})={1}")
    public static Collection&lt;Object[]&gt; data() {
        return Arrays.asList(new Object[][] {     
              { 7, true }, { 36, true }, { 984, true }, { 7404, true }, { 37, false }
        });
    }

    private int input;

    private boolean expected;

    private DigitIncreasing digitIncreasing = new DigitIncreasing();

    public DigitIncreasingTest(int input, boolean expected) {
        input = input;
        expected = expected;
    }

    @Test
    public void test() {
        assertEquals(expected, digitIncreasing.isDigitIncreasing(input));
    }
}


This is easier to understand (in my opinion) than your formulation, where you shadow the name of the class under test, and actually runs each case as a separate test.