Jun 21, 2024

TestNG unable to find valid certification path to requested target

I have the following error when I run a test.

org.testng.TestNGException: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.testng.TestNG.parseSuite(TestNG.java:327)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:348)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:39)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105)
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at java.base/sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)

The reason is Java keystore does not have testNG certificate. You need to add it.
Here is how to.

1. Download testng.org certificate. Click Export button.

2. Run the following command.
"C:\Program Files\Zulu\zulu-11\bin\keytool.exe" -importcert -file C:\dev\testng.org.crt -trustcacerts -keystore "C:\Program Files\Zulu\zulu-11\lib\security\cacerts"
   You will be asked to input password. The default password is "changeit". And input yes to trust testng certificate.


Now your test will pass or fail. Good luck!