junit - JUnitParamsRunner - cannot pass variable parameters or array of Objects to the test()? -


i found cannot declare public void test(obj...objects) , use junitparamsrunner parameterize test..exception thrown @ runtime. works fine if change public void test(obj obj1, obj obj2) idea? below code:

private static object[] testingparam() {   return new object[] { new object[] { new obj("123"), new obj("123") } ]; }      @test @parameters(method = "testingparam")     public void test(obj...objects){   //do test } 

though don't have chance test this, appears based on usage documentation may need obj[] array instead of object[] array match vararg. note object[] , obj[] not covariant , cannot cast 1 another.

private static object[] testingparam() {   return new object[] { new obj[] { new obj("123"), new obj("123") } }; } 

conversely, if trying ignore varargs , treat parameter naive array, need third array wrapper:

private static object[] testingparam() {   return new object[] {  // <-- call testing method once       new object[] {     // <-- array of parameters           new obj[] {    // <-- , first parameter 2-element obj array               new obj("123"), new obj("123") } } }; } 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -