Unit testing JUnit失败测试:预期:<;sun.security.ssl。SSLSocketFactoryImpl@48030df0&燃气轮机;但事实是:<;sun.security.ssl。SSLSocketFactoryImpl@40882c7f&燃气轮机; 运行单元测试(assertEquals)时出现此错误: java.lang.AssertionError:应为:sun.security.ssl。SSLSocketFactoryImpl@48030df0>但是是:sun.security.ssl。SSLSocketFactoryImpl@40882c7f>

Unit testing JUnit失败测试:预期:<;sun.security.ssl。SSLSocketFactoryImpl@48030df0&燃气轮机;但事实是:<;sun.security.ssl。SSLSocketFactoryImpl@40882c7f&燃气轮机; 运行单元测试(assertEquals)时出现此错误: java.lang.AssertionError:应为:sun.security.ssl。SSLSocketFactoryImpl@48030df0>但是是:sun.security.ssl。SSLSocketFactoryImpl@40882c7f>,unit-testing,junit,mockito,Unit Testing,Junit,Mockito,当我运行此代码的单元测试以测试getSslSocketFactory方法时 public ClientCertSocketFactory() throws IOException{ String trustStoreFilePath = System.getProperty("javax.net.ssl.trustStore"); try { TrustManagerFactory trustManagerFactory = CertManagerFactory.

当我运行此代码的单元测试以测试getSslSocketFactory方法时

public ClientCertSocketFactory() throws IOException{
    String trustStoreFilePath = System.getProperty("javax.net.ssl.trustStore");
    try {
        TrustManagerFactory trustManagerFactory = CertManagerFactory.loadTrustStore(trustStoreFilePath);
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
        this.sslSocketFactory = sslContext.getSocketFactory();
    } catch (NoSuchAlgorithmException e) {
        LOGGER.error("No Provider supports a TrustManagerFactorySpi implementation for the TLS protocol. Error message: " + e);
    } catch (KeyManagementException e) {
        LOGGER.error("Error occurred when initializing SSLContext. Error message: " + e);
    }
}

public SSLSocketFactory getSslSocketFactory() {
    return sslSocketFactory;
}

我对getSslSocketFactory的单元测试是: 我怎么能修好它?
非常感谢

这不是一个答案,但要明确的是,这里的不是“单元测试”。您不是在验证应用程序业务逻辑,而是在验证代码与底层SSL框架的集成。编写一个“吸气剂”方法的单元测试是荒谬的,正如您在这里所说的。您可能会考虑在调试器中跳过这两个函数,检查意外发生的地方。在重新配置信任管理器后,您将得到另一个实例,从而测试失败。(它们在身份上是平等的。)
@Test
public void shouldGetSslSocketFactory() throws IOException, NoSuchAlgorithmException, KeyManagementException{
    String trustStoreFilePath = System.getProperty("javax.net.ssl.trustStore");

    TrustManagerFactory trustManagerFactory = CertManagerFactory.loadTrustStore(trustStoreFilePath);
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
    this.sslSocketFactory = sslContext.getSocketFactory();

    assertEquals(sslSocketFactory, clientCertSocketFactory.getSslSocketFactory());


}