Unit testing Roman-Arabic-Roman numeric converter As you can see here, I wrote the methods public static int romanToArabic(String number) and public static String arabicToRoman(int number) to convert roman numbers to arabic numbers and vice versa.

I now wrote a unit-testing-class to test these methods. It is my first attempt to write a (real) unit test, so I would like to know your opinion.

Here's the code:

import org.junit.Test;
import static org.junit.Assert.*;

public class TestCases {

    @Test
    public void testRomanToArabic() {
        String[] input = {null, "", "I", "V", "XXXIII", "DCCXLVII", "CMXXIX", "MCCXXXII", "MMMCMXCIX", "MMMMXI", "KMXI", 
                "VX", "VL", "VC", "VD", "VM", "LC", "LD", "LM", "DM", "IL", "IC", "ID", "IM", "XD", "XM", "CXLV", "MIXI", "IXI", "MXIII", "MMMM", "IIII"}; 
        int[] expectedOutput = {-1, -1, 1, 5, 33, 747, 929, 1232, 3999, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 145, -1, -1, 1013, -1, -1};
        for(int i = 0; i &lt; input.length; i++) {
            int k = RomanNumbers.romanToArabic(input[i]);
            try {   
                assertEquals(k, expectedOutput[i]);
            }
            catch(AssertionError assertFailed) {
                System.out.println("Test failed!");
                System.out.println("Input: " + input[i]);
                System.out.println("Output: " + k + "| Expected: " + expectedOutput[i]);
            }
        }
    }

    @Test
    public void testArabicToRoman() {
        int[] input = {-1, 1, 5, 33, 747, 929, 1232, 3999, 4000};
        String[] expectedOutput = {"Error", "I", "V", "XXXIII", "DCCXLVII", "CMXXIX", "MCCXXXII", "MMMCMXCIX", "Error"};
        for(int i = 0; i &lt; input.length; i++) {
            String k = RomanNumbers.arabicToRoman(input[i]);
            try {   
                assertEquals(k, expectedOutput[i]);
            }
            catch(AssertionError assertFailed) {
                System.out.println("Test failed!");
                System.out.println("Input: " + input[i]);
                System.out.println("Output: " + k + "| Expected: " + expectedOutput[i]);
            }
        }
    }
}


Is this the way to go, or is it considered bad practice to put more than one test in a method? 
Do you have any other suggestions on improving the code?
I have two suggestions:


I like tests to be very easily human-readable. Instead of separate arrays of input and output, which are not aligned with each other, find a way to put the input and the expected output on one line.


The easiest way in this case would be to add a method

private void testRomanToArabic(String input, int expectedOutput) {
    assertEquals(RomanNumbers.romanToArabic(input), expectedOutput);
}


and then use this method repeatedly like

testRomanToArabic("XXXIII", 33);


etc. There are other ways to put input and expected output next to each other (e.g. create an object holding both), but this is the simplest.


Don't catch the AssertionError and print the result yourself. The test should be run by a test runner which will handle this part for you. I always do this from the Eclipse IDE by selecting "Run As JUnit Test", but there is for sure a way to do the same thing from the command line.


By catching the AssertionError, you hide the error from external tools, meaning you have to read the output yourself. If the AssertionError is thrown, your testing framework is aware of the error, which becomes very important when you have hundreds of tests: it can highlight for you the handful that are failing.