谷歌应用引擎 +本地 JUnit 测试 +泽西岛框架 +嵌入式码头

发布于 2024-08-23 09:30:51 字数 630 浏览 3 评论 0原文

我使用 Google Appengine for Java (GAE/J)。 最重要的是,我使用 Jersey REST 框架。

现在我想运行本地 JUnit 测试。该测试

不幸的是,Jersey/Jetty 组合产生了新的线程。 GAE 预计只有一个线程运行。 最后,我最终要么在 Jersey 资源中没有数据存储,要么有多个具有不同的数据存储。

作为一种解决方法,我仅初始化 GAE 本地环境一次,将其放入静态变量中,并在 GAE 资源内添加许多检查(此线程没有开发环境?重新使用静态环境)。当然,这些检查应该只在 JUnit 测试中运行..(我之前问过:“如何确定代码是否在 JUnit 测试中运行?” - 我不被允许直接在此处发布链接:-|)

I use Google Appengine for Java (GAE/J).
On top, I use the Jersey REST-framework.

Now i want to run local JUnit tests. The test

Unfortunately, the Jersey/Jetty combo spawns new threads. GAE expects only one thread to run.
In the end, I end up having either no datstore inside the Jersey-resources or multiple, having different datastore.

As a workaround I initialise the GAE local env only once, put it in a static variable and inside the GAE resource I add many checks (This threads has no dev env? Re-use the static one). And these checks should of course only run inside JUnit tests.. (which I asked before: "How can I find out if code is running inside a JUnit test or not?" - I'm not allowed to post the link directly here :-|)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乖乖公主 2024-08-30 09:30:51

也许使用系统属性...
当它是 Junit 运行时,通过 JVM 参数设置 Java 系统属性,然后您可以测试如下内容:

  • 在测试时(可能在 IDE 等中)通过运行配置参数传递 JVM 参数,如下所示: -DRunningTestsOnly= true
  • 代码: if ("true".equals(System.getProperty("RunningTestsOnly")))

我之前在 JUnit 测试中做过类似的事情,使用假设忽略测试我认为在我的动力不足的开发 PC 上运行需要太长时间...

  • 传递 JVM 参数:-DexecuteQuickRunningTestsOnly=true
  • 如果我将属性集放在方法的顶部,则忽略运行缓慢的测试方法: assumeThat(System.getProperty("executeQuickRunningTestsOnly", "false"), is("false"));

Maybe use a System property...
When it's a Junit run set a Java system property via a JVM arg which you can then test for something like this:

  • pass in a JVM arg via run config parms when testing (in IDE etc maybe) like this: -DRunningTestsOnly=true
  • in code: if ("true".equals(System.getProperty("RunningTestsOnly")))

I've done similar to this in JUnit tests before, using assume to ignore tests I think take too long to run on my underpowered dev PC...

  • pass in JVM arg: -DexecuteQuickRunningTestsOnly=true
  • To ignore a slow running test method if property set I put at the top of the method : assumeThat(System.getProperty("executeQuickRunningTestsOnly", "false"), is("false"));
梅倚清风 2024-08-30 09:30:51

只是一个想法:
您可以创建一个异常,然后迭代异常的堆栈跟踪以查看其中是否是 junit 包中的类。

Just an idea:
You could create an Exception and then iterate over the exception's stack trace to see if thers's a class from the junit package in there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文