0

Getting JNI error while running TestNG program (that doesn't have main() function).

enter image description here

But If trying to run the same program with same set of configuration (i.e. eclipse and java version), "Run as a java application" then it's working fine.

After click on OK button on the pop up of "JNI error", getting below error- Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException

Java and javac versions are same.

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;

public class BasicsUsingTestNg {

    @Test
    public void Test1() {
        // TODO Auto-generated method stub
RestAssured.baseURI = "https://maps.googleapis.com";

        given().param("location", "-33.8670522,151.1957362").param("radius", 500)
                .param("key", "AIzaSyB_mtr6ORifRUHaZIpTtppLfnSLshwObEc").

                when().get("maps/api/place/nearbysearch/json").

                then().assertThat().
statusCode(200).and().
contentType(ContentType.JSON).
and().body("results[0].geometry.location.lat", equalTo("-33.8688197"));
    }
}

If i am trying to run the same program with java main method, it's running successfully. Like below code-

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;

public class BasicsUsingTestNg {


    public static void main(String args[]) {
        // TODO Auto-generated method stub
RestAssured.baseURI = "https://maps.googleapis.com";

        given().param("location", "-33.8670522,151.1957362").param("radius", 500)
                .param("key", "AIzaSyB_mtr6ORifRUHaZIpTtppLfnSLshwObEc").

                when().get("maps/api/place/nearbysearch/json").

                then().assertThat().
statusCode(200).and().
contentType(ContentType.JSON).
and().body("results[0].geometry.location.lat", equalTo("-33.8688197"));
    }
}
13
  • Possible duplicates of stackoverflow.com/questions/30112390/… – Mohamed Sulaimaan Sheriff Mar 3 '20 at 4:35
  • I have tried all the possible options mentioned in above link. Inclusion of Jcommander jar also. But still facing the same problem. Because none of the solution worked for me. – Gaurav Mar 3 '20 at 7:36
  • Is it possible to paste the code here – Mohamed Sulaimaan Sheriff Mar 3 '20 at 8:05
  • I don't think so, that there is any problem in code. Because same is working perfectly fine with java main() function. When running the same program with "Run as Java application". But getting error while running as TestNG test – Gaurav Mar 3 '20 at 10:13
  • Getting JNI error while running TestNG program - what does it mean? What steps are you taking exactly? – Alexey R. Mar 3 '20 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.