Hi I have a method that accepts a List<String> param as a parameter. I'm writing a JUnit test which needs to be able to accept the parameters as a String and then it needs converted to a List<String>
The JUnit code is:

 public void testMethodName(String params, String expectedResult){
        final String testCollection = instance.MethodName(params);
        if (null == expectedResult){
            assertNull("Should return null for unspecified value", testCollection);
        }
        else{
            assertEquals("Should return expected value", expectedResult, testCollection);
        }
    }

    public Object[] parametersForTestMappingCollection(){
        final List<Object> testCases = new ArrayList<Object>();

        testCases.add(JUnitParamsRunner.$("Company Request-Other than Non Payment", "UR")); 

Its basically to test a hashmap to make sure the key returns the correct value. So I basically wanted to know how I can convert each of the strings to a List<String> so that it can be passed to the method.

Recommended Answers

All 4 Replies

JUnit tests don't take parameters.

JUnit tetsts are supposed to test existing units, not to create new untested units.

I'm not sure it that is right because when I google JUnit parameter test it gives examples of it online. It's just that I need to be able to convert it from a string to a List<String>.

There are ways and libraries that allow you to do so, but you'll need to configure it in your annotation. So far, I don't see any annotations on your method. If there aren't any, it's not a JUnit test anyway.
In any case, it would make this part pointless:

if (null == expectedResult){

since you have to configure the value of expectedResult in your testclass.

There are annotations, I just didn't include all of the code the two annotations above the method are @Test and @Parameters. The expectedResult value is the "UR" part of testCases.add(JUnitParamsRunner.$("Company Request-Other than Non Payment", "UR"));

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.