繁体   English   中英

在Maven集成测试期间,输出\\输入在Junit中不起作用

[英]Output\Input Not working in Junit during Maven Integration Tests

我正在使用JUnit和一些我编写,修改或从现有代码库中获得的客户端,将集成测试所需的文件推送到要用于进行集成测试的系统。

这是preIntegration设置步骤。 Maven有自己的预集成步骤,但是我只是觉得对于我想要\\需要\\喜欢的东西太不灵活。

@Before
public void preIntegration() throws IOException, JSchException,
        UnsupportedOperationException, IllegalArgumentException,
        SecurityException, URISyntaxException, JSONException,
        RuntimeException, NoSuchAlgorithmException, KeyStoreException,
        KeyManagementException {
    if (!firstTimeSetupDone) {
        testConfig = new Properties();

        testConfig.load(getClass().getResourceAsStream("/test-config"));

        oozieClient = new OozieClientWithBlocking(
                testConfig.getProperty("oozieUrl"));

        BufferedReader in = new BufferedReader(new InputStreamReader(
                System.in));

        System.out.print("Username: ");
        String username = in.readLine();
        System.out.print("Password: ");
        String password = in.readLine();
        System.out.print("Host: ");
        String host = in.readLine();

        secureContext = new SecureContext(username, host);
        secureContext.setPassword(password);
        secureContext.setTrustAllHosts(true);

        assertNotNull("Linux test file present",
                getClass().getResource("/file.txt"));

        URL resourceUrl = getClass().getResource("/file.txt");

        System.out.println("Sending files to linux.");
        Scp.exec(secureContext, resourceUrl.getPath(),
                "/home/myUsername/file.txt");

        SSLContextBuilder sslContextBuilder = new SSLContextBuilder();

        TrustStrategy acceptAnyCertificate = new TrustStrategy() {
            public boolean isTrusted(final X509Certificate[] chain,
                    String authType) throws CertificateException {
                return true;
            }
        };
        sslContextBuilder.loadTrustMaterial(null, acceptAnyCertificate);
        SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
                sslContextBuilder.build());

        BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
        Credentials credentials = new UsernamePasswordCredentials(username,
                password);
        basicCredentialsProvider.setCredentials(AuthScope.ANY, credentials);

        HttpClientBuilder httpClientFactory = HttpClientBuilder.create();

        httpClientFactory
                .setDefaultCredentialsProvider(basicCredentialsProvider);
        httpClientFactory.setSSLSocketFactory(sslConnectionSocketFactory);

        CloseableHttpClient httpClient = httpClientFactory.build();

        hdfsClient = new HDFSRestClient(httpClient,
                testConfig.getProperty("nameNodeHttps"));

        URL jar = getClass().getResource("/Utilities-1.4.0.jar");

        System.out.println("Sending files to hdfs.");
        hdfsClient
                .create(jar.getPath(),
                        "/user/myUsername/java-action-workflow/lib/Utilities-1.4.0.jar");
        properties = new Properties();
        properties.setProperty("user.name", username);
        System.out.println("Prep done.");
        firstTimeSetupDone = true;
    }
}

在集成前@Before步骤中,我要求提供用于三个客户端( SCPWebHDFS )中的两个的用户名和密码。 今年晚些时候,我们公司可能会实施Kerberos,这可能不必要。 在此期间,这是我发现会让人们开心的唯一方法。 是的,我知道我绕过了SSL的实用性,但是我知道我要连接的服务器,它的内部网络被严格防火墙保护,这在很大程度上是概念证明。 如果考虑将其投入生产,我会提出关注。

问题:当我自己运行集成测试Junit类时,一切正常。 我得到提示输入用户名和密码,并且能够输入它们。 之后,将执行该类中的长测试用例,并且我已经验证了客户端实际上在工作。 没问题。 然后,当我使用“ integration-test”运行Maven构建时,故障安全插件仅在需要运行其测试时停止 我正在通过Eclipse运行所有这些:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

标头打印,然后生成似乎空闲\\等待\\停止。 我什至尝试通过Eclipse中的其他控制台窗口查看JUnit是否在其他地方吐出System.out.print语句。

我想您的Test等待的原因是它的预期inputs 要发送输入参数,您可以执行以下操作

mvn integration-test -Dusername=XXX -Dpassword=YYYY

要使它与m2e一起使用,请在pom.xml的故障安全插件声明中使用此命令:

<configuration>
                        <systemPropertyVariables>
                        <username>${myUsername}</username>
                        <password>${myPassword}</password>
                        <host>${myHost}</host>
                        </systemPropertyVariables>
            </configuration>

然后将变量放在“运行方式”配置属性中的“ VM”字段中,如下所示:

-Dusername=myUsername
-Dpassword=myPassword
-Dhost=myHost

然后,您将用System.getProperty调用替换System.in调用。 (例如System.getProperty(“ username”))。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM