测试DAO层的正确方法是什么?
我有创建和销毁的方法@BeforeMethod和@AfterMethod注释方法,SessionFactory但它不能用于多个测试.如果一个接一个地运行测试,但是当它们一起运行时没有使用maven构建,所以我决定我应该使用TestNg组对它们进行分组,@BeforeGroup并且@AfterGroup使用Hibernate做同样的事情.
所以我做了这样的事情:
@Test(groups = {"integration"})
public class IntegrationTest
{
protected SessionFactory sessionFactory;
@BeforeGroups(groups = {"integration"})
public void setUpHibernate() throws Exception
{
// here I configure sessionFactory
this.sessionFactory = ...
}
@AfterGroups(groups = {"integration"})
public void putItDown() throws Exception
{
sessionFactory.close();
}
}
Run Code Online (Sandbox Code Playgroud)
我的每个测试都像这样扩展了这个类
@Test(groups = "integration")
public class RateRepositoryHibernateTest extends IntegrationTest
{
...
}
Run Code Online (Sandbox Code Playgroud)
然后我注意到只有一个扩展测试sessionFactory设置和休息,null这并不奇怪,因为该方法应该运行一次.现在我真的不知道该怎么做.
如何从@BeforeGroup组测试方法的方法传递数据?
要么
怎么做不同的?
要么
如何安装和拆卸SessionFactory前,每次测试后,但在某种程度上,我不会得到任何pesimistic锁定异常多的测试?
- …
有两个sbt项目:common和projectX.
该项目common已在一些依赖test范围,我想看到的test在classpath中projectX具有common作为依赖.
这是摘录从build.sbt在projectX与test->test配置映射中所描述的配置:
libraryDependencies ++= Seq(
"org" %% "common" % "0.1" % "compile->compile;test->test"
)
Run Code Online (Sandbox Code Playgroud)
执行test:compile时projectX出现以下错误:
[error](*:update)sbt.ResolveException:unresolved dependency:org#common_2.10; 0.1:org中的公共配置#common_2.10; 0.1:'test'.需要从org#projectX_2.10; 0.0.1-SNAPSHOT测试
如何将test项目中的-scoped依赖项添加到项目common中的test类路径projectX?
我想以正确的方式去做。我已经看到暴露 boost::serialization::singleton 这里 Boost python export singleton但我不想使用它。我想使用简单的迈耶斯单例来代替。
下面的代码有效,但文档表明使用 http://www.boost.org/doc/libs/1_43_0/libs/python/doc/v2/reference_existing_object.html#reference_existing_object-spec/ 是危险的。
代码:
class Singleton
{
private:
Singleton(){};
public:
static Singleton & getInstance()
{
static Singleton instance;
return instance;
}
int getNumber() { return 5; }
};
Run Code Online (Sandbox Code Playgroud)
并在模块中:
class_<Singleton>("singleton", no_init)
.def("getInstance", &Singleton::getInstance, return_value_policy<reference_existing_object>()).staticmethod("getInstance")
.def("getNumber", &Singleton::getNumber)
;
Run Code Online (Sandbox Code Playgroud)
有什么好的方法可以做到吗?执行 python 代码时使用return_internal_reference<>()导致错误。
使用sbt v0.13.2我的输入任务有问题
我希望有一个接受输入的任务,将该输入设置为系统属性并在所有这些之后运行另一个任务,例如使用该系统属性的测试.
我需要在单独的任务中设置系统属性,因为在测试期间不能看到overwise属性.然而,在随后的相同任务运行期间可以看到它.
lazy val setEnvironmentTask = taskKey[Unit]("Sets environment variable")
lazy val integrationTest = taskKey[Unit]("Runs integration test")
lazy val runIntegrationTest = taskKey[Unit]("Runs everything")
setEnvironmentTask := {
System.setProperty("checkEnv", "production")
}
integrationTest := {
(testOnly in Test).toTask(" integrations.MatchModelsIntegrationTest").value
}
runIntegrationTest := {
setEnvironmentTask.value
integrationTest.value
}
Run Code Online (Sandbox Code Playgroud)
这可行,但正如您在setEnvironmentTask中看到的那样,第二个参数是固定的.
我找不到解决方案了.一些方法产生了error: Illegal dynamic reference,如下所示,两个任务被更改为inputTasks并添加了import:
import sbt.complete.Parsers.spaceDelimited
lazy val setEnvironmentTask = inputKey[Unit]("Sets environment variable")
lazy val runIntegrationTest = inputKey[Unit]("Runs everything")
setEnvironmentTask := {
val env = spaceDelimited("<arg>").parsed.head
System.setProperty("checkEnv", env)
}
runIntegrationTest := {
val …Run Code Online (Sandbox Code Playgroud) 我有两个子项目和顶级项目,他们同意这些项目.我可以成功发布所有这些版本,但只更改了顶级项目上的版本,并且子目录以其目录中定义的版本发布,遗憾的是在发布期间不会更改.
Root
|
-SubA
| |- version.sbt -> version in SubA := "0.0.1-SNAPSHOT"
|
-SubB
| |- version.sbt -> version in SubB := "0.0.4-SNAPSHOT"
|- version.sbt -> version in ThisBuild := "0.1.0-SNAPSHOT"
Run Code Online (Sandbox Code Playgroud)
发布后我想:
并且每个版本例如在SubA/version.sbt- > 0.0.2-SNAPSHOT中递增
我该如何使用sbt 0.13和sbt-release插件?