【问题标题】:Can we execute Hybris integration test case directly from eclipse?我们可以直接从 eclipse 执行 Hybris 集成测试用例吗?
【发布时间】:2017-03-08 12:11:33
【问题描述】:

我可以使用 'ant alltests' 命令从 hybris 平台目录执行测试用例,但不能从 eclipse 执行。

从eclipse执行测试用例时出现以下错误->右键单击->运行为-> JUnit测试

INFO  [main] (junit) [HybrisContextFactory] - Refreshing SpringContext (hybris Application context - junit) took: (29.48 s)
INFO  [main] (junit) [HybrisContextFactory] Initializing application Spring ApplicationContext for tenant junit  took: (31.27 s)
INFO  [main] (junit) [DefaultRMIRegistryService] Unexporting the registry.
de.hybris.platform.core.UninstantiableCoreApplicationContextException: Error creating Spring application context.
    at de.hybris.platform.core.AbstractTenant.doStartupSafe(AbstractTenant.java:728)
    at de.hybris.platform.core.AbstractTenant.doStartUp(AbstractTenant.java:658)
    at de.hybris.platform.core.Registry.assureTenantStarted(Registry.java:639)
    at de.hybris.platform.core.Registry.activateTenant(Registry.java:700)
    at de.hybris.platform.core.Registry.setCurrentTenant(Registry.java:544)
    at de.hybris.platform.util.Utilities.setJUnitTenant(Utilities.java:1472)
    at de.hybris.platform.testframework.runlistener.PlatformRunListener.testRunStarted(PlatformRunListener.java:44)
    at de.hybris.platform.testframework.ChainingRunNotifierWrapper$1.notifyListener(ChainingRunNotifierWrapper.java:97)
    at de.hybris.platform.testframework.ChainingRunNotifierWrapper$SafeNotifier.run(ChainingRunNotifierWrapper.java:239)
    at de.hybris.platform.testframework.ChainingRunNotifierWrapper.fireTestRunStarted(ChainingRunNotifierWrapper.java:99)
    at de.hybris.platform.testframework.HybrisJUnit4ClassRunner.run(HybrisJUnit4ClassRunner.java:124)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name

【问题讨论】:

  • 我在从 eclipse 执行测试时遇到了几个不同的问题,比如这个问题,最终使用了 hybris testweb 控制台,您可以从 your-ip:9001/test/ 访问该控制台。希望对您有所帮助。
  • 无法从 testweb 控制台运行 Web 模块测试。

标签: eclipse spring ant integration-testing hybris


【解决方案1】:

是的,这是可能的。

实际上,使用 hybris 6.1 和 Eclispe Neon,我能够从 hybris 项目中运行 Junit 测试,而不会在 GUI 中遇到任何问题。

要在 Eclispe 上进行测试,您必须确保

  • 您的所有项目都在 Eclipse 中正确配置(没有错误)
  • 所有依赖项都存在于您的工作区中
  • localextensions.xml 文件的所有已配置扩展都在 Eclipse JUnit 测试配置的类路径中注册。

要修复最后一点,请执行以下步骤

  • 打开运行菜单
  • 打开运行配置对话框
  • Run Configurations 对话框中,选择您的测试配置
  • 转到类路径选项卡。
  • 点击添加项目按钮。
  • 在“项目选择”对话框中,选择您在 localextensions.xml 文件中配置的所有扩展。

hybris 的其他提示

如果你的 Spring 配置在启动时没有被引导 Hybris 平台的 Spring 文件可能不是测试的一部分 类路径。这可能是由于在 类路径,或者在 Eclipse 中不包括资源文件夹 类路径。确保您的 .classpath 文件包含 以下行: <classpathentry exported="true" kind="lib" path="resources"/>


关于您的具体问题

最好发布MCVE,因为该问题可能与您的特定测试有关。以上提示可以帮助你。在尝试自己的测试之前,先尝试从 hybris 成功运行测试。


资源和进一步阅读

Testing in SAP Hybris Commerce - 检查 Eclipse 部分

Eclipse workspace errors - A Complete guide - 包含更多资源来解决 Eclipse 中的错误

The Hybris Testweb Frontend - 如果你想从这个接口测试你的测试,考虑在之前初始化junit tenant

【讨论】:

    【解决方案2】:

    您必须使用 Eclipse 中的 ant,(窗口 > 首选项 > ant > 运行时 > ant home > 并指定您的 ant 文件夹在哪里,例如:C:\Program Files\Ant\apache-ant-1.9.1

    然后(窗口>显示视图>其他>选择蚂蚁)

    然后在您的 ant 视图中单击添加构建文件(在带有 + 的 ant 图标上)这将显示您工作集中的所有项目(必须导入平台扩展)选择 platform/build.xml

    在ant视图中你会看到所有的命令都显示出来了,你可以从eclipse而不是命令行执行任何操作。

    【讨论】:

    • 使用 platform/build.xml 目标,我们只能在某些情况下对所有扩展或特定扩展执行测试,如果我们只需要对 TDD 执行一个测试。
    • 好吧,实际上你不能运行一个需要运行 tomcat 的测试类,因为它会尝试启动主租户,如果你使用 mockito 应该没问题
    • 绝对有可能,我的一些团队成员一直在这样做。关键是要正确设置调试/运行时配置(抱歉,我这里没有准备好:))
    • 您是否在您的@before 方法中调用了Registry.activeMasterTenant() 方法?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多