在我们的 Azure Pipeline 中,我们尝试使用以下任务在 Angular 9 应用程序中运行端到端测试...
package.json 定义了这个...
"scripts": {
...
"e2e": "npm run install-puppeteer && ng e2e"
},
Run Code Online (Sandbox Code Playgroud)
但是当代理运行上述任务时,它会因“无法打开 X 显示”错误而终止......
> npm run install-puppeteer && ng test "--watch=false" "--codeCoverage=true"
> thermo-protect-ui@0.0.0 install-puppeteer /home/vsts/work/1/s
> cd node_modules/puppeteer && npm run install
> puppeteer@5.5.0 install /home/vsts/work/1/s/node_modules/puppeteer
> node install.js
Chromium is already in /home/vsts/work/1/s/node_modules/puppeteer/.local-chromium/linux-818858; skipping download.
08 12 2020 18:54:56.858:INFO [karma-server]: Karma v4.4.1 server started at http://0.0.0.0:9876/
08 12 2020 18:54:56.863:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
08 …Run Code Online (Sandbox Code Playgroud) 我正在使用Hibernate 4.0.1.Final编写一个独立的Java应用程序.在测试我的数据访问层时,我遇到以下异常
org.hibernate.HibernateException:没有活动事务,createCriteria无效
搜索对象时 我正在尝试将我的事务级代码与我的数据库操作代码分开.我的JUnit测试是
@Before
public void setUpDAOTest() {
final Configuration configuration = new Configuration();
configuration.configure().setProperty("hibernate.show_sql", "false");
final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
orgDao = new OrganizationDAOImpl(sessionFactory);
session = sessionFactory.openSession();
tx = session.beginTransaction();
} // setUp
@Test
public void testFindStateByAbbrev() {
final String abbrev = testProps.getProperty("test.state.abbrev");
final State state = orgDao.findStateByAbbrev(abbrev);
Assert.assertNotNull(state);
Assert.assertEquals(testProps.getProperty("test.state.abbrev"), state.getAbbrev());
} // testFindStateByAbbrev
Run Code Online (Sandbox Code Playgroud)
和单元测试调用的代码是......
public class OrganizationDAOImpl extends AbstractDAO implements OrganizationDAO {
…
public State findStateByAbbrev(final String abbrev) {
State ret = …Run Code Online (Sandbox Code Playgroud) 我正在使用JPA 2.0,Hibernate 4.1.0.Final,Spring 3.1.1.RELEASE和Java 1.6.我有这个实体与另一个实体的一对多关系......
import javax.persistence.CascadeType;
...
@Entity
@Table(name = "classroom")
public class Classroom implements Serializable
{
...
@OneToMany(mappedBy = "classroom", cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
private Set<ClassroomUser> roster;
Run Code Online (Sandbox Code Playgroud)
但是,当我使用一组不同的ClassroomUser对象更新我的实体时
classroom.setRoster(newRoster);
Run Code Online (Sandbox Code Playgroud)
并保存实体,保留所有以前的ClassroomUser对象.在从数据库中删除所有孤立记录时更新我的实体的正确/最短方法是什么?
谢谢, - 戴夫
我在OS X 10.9.1上使用MySQL 5.5.37.我有一个NOT NULL类型的列DATETIME.如果不使用触发器,如何阻止'0000-00-00 00:00:00'的值进入我的列?我会接受CURRENT_TIMESTAMP的值来代替所有的零.
我试过了:
SET sql_mode = 'NO_ZERO_DATE';
Run Code Online (Sandbox Code Playgroud)
运行上面的内容后,我仍然可以在表格中插入零日期.
我正在使用Maven 3.0.3,Failsafe插件v2.17和JUnit 4.11。目前,我有一个集成测试,测试顺序如下
@RunWith(SpringJUnit4ClassRunner.class)
public class MyTests {
@Test
public final void testAdd() {
…
}
@Test
public final void testUpdate() {
…
}
@Test
public final void testDelete() {
…
}
Run Code Online (Sandbox Code Playgroud)
目前,当我作为“ mvn全新安装”运行的一部分通过Maven运行测试时,在“ testAdd”或“ testUpdate”之前先运行“ testDelete”。如果我将名称更改为“ testZZZDelete”,那么它将最后运行,但我不喜欢这样。
如何使测试按照文件中指定的顺序运行?我的故障安全配置如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我正在使用Gradle 2.7,MySQL 5.5.46和Gradle Liquibase插件(v 1.1.1)。我在H2(v。1.4.190)内存数据库和MySql数据库上都运行LIquibase脚本。如何配置变更集,以便Liquibase可以在MySQL数据库上运行它,但是对于内存数据库则忽略它?我已经试过了
<preConditions>
<dbms type="mysql" />
</preConditions>
<changeSet id="create_artifact_stored_proc" author="davea">
<sqlFile endDelimiter="//" path="src/main/resources/scripts/create_artifact_stored_proc.sql" stripComments="true"/>
</changeSet>
Run Code Online (Sandbox Code Playgroud)
但是,如果在H2数据库上运行此命令,则以上操作将失败(可预测),并显示以下错误:
liquibase.exception.ValidationFailedException: Validation Failed:
1 preconditions failed
src/main/resources/db.changelog-master.xml : DBMS Precondition failed: expected mysql, got h2
at liquibase.changelog.DatabaseChangeLog.validate(DatabaseChangeLog.java:196)
at liquibase.Liquibase.update(Liquibase.java:196)
at liquibase.integration.commandline.Main.doMigration(Main.java:1044)
at liquibase.integration.commandline.Main.run(Main.java:175)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:43)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:88)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.liquibase.gradle.LiquibaseTask.runLiquibase(LiquibaseTask.groovy:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:382)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1015) …Run Code Online (Sandbox Code Playgroud) 我正在使用Hamcrest 2.0.0.0并尝试使用Spring(v 3.2.11.RELEASE)的mockmvc框架来使用json-path匹配.我在JUnit(v 4.11)测试中有这个
mockMvc.perform(get("/api/users/" + id))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", is(id)));
Run Code Online (Sandbox Code Playgroud)
我有这些依赖...
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.2.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但我得到以下错误.使json-path匹配工作所需的正确依赖性/版本列表是什么?
java.lang.NoSuchMethodError: com.jayway.jsonpath.JsonPath.compile(Ljava/lang/String;[Lcom/jayway/jsonpath/Filter;)Lcom/jayway/jsonpath/JsonPath;
at org.springframework.test.util.JsonPathExpectationsHelper.<init>(JsonPathExpectationsHelper.java:54)
at org.springframework.test.web.servlet.result.JsonPathResultMatchers.<init>(JsonPathResultMatchers.java:43)
at org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath(MockMvcResultMatchers.java:146)
at org.springframework.security.oauth2.resources.ZincDataControllerIT.testGetInfoForTeacher(ZincDataControllerIT.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring 3.2.11.RELEASE和Maven 3.3.我在我的应用程序上下文文件中定义了这个...
<bean id="localPropertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:quickbase.properties</value>
</list>
</property>
</bean>
…
<bean id=“myClient" class="org.mainco.subco.mysystem.MyClient">
<constructor-arg index="0" type="String" value="${quickbase.username}" />
<constructor-arg index="1" type="String" value="${quickbase.password}" />
<constructor-arg index="2" type="String" value="${quickbase.url}" />
</bean>
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的测试时,我得到以下错误
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'myClient' defined in class path resource [META-INF/spring/applicationContext-orders.xml]: Could not resolve placeholder 'quickbase.username' in string value "${quickbase.username}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'quickbase.username' in string value "${quickbase.username}"
Run Code Online (Sandbox Code Playgroud)
这让我感到困惑,因为在我的target/classes目录中,我可以看到一个文件"quickbase.properties",它定义了"quickbase.username".我无法弄清楚我还需要检查什么.
我正在使用 Spring 4.3.8.RELEASE。在我的集成测试中,我使用的是 SPring 的 MockMvc 框架,设置如下......
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
...
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
...
mockMvc.perform(get(contextPath + "/path")
.contextPath(contextPath)
.principal(auth)
.param("param1", param1)
.param("param2", param2))
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚的是如何设置我的请求的服务器名称。也就是说,当我的控制器被调用时填充
final HttpServletRequest request
Run Code Online (Sandbox Code Playgroud)
我如何设置
request.getServerName()
Run Code Online (Sandbox Code Playgroud)
来自 MockMvc 调用?
我想编写一个 Django 查询来计算表中所有行的平均值。我的模型看起来像
class StatByDow(models.Model):
total_score = models.DecimalField(default=0, max_digits=12, decimal_places=2)
num_articles = models.IntegerField(default=0)
day_of_week = IntegerField(
null=True,
validators=[
MaxValueValidator(6),
MinValueValidator(0)
]
)
Run Code Online (Sandbox Code Playgroud)
我尝试像这样计算平均值
everything_avg = StatByDow.objects.all().aggregate(Avg(Func(F('total_score') / F('num_articles'))))
Run Code Online (Sandbox Code Playgroud)
但这会导致错误
File "/Users/davea/Documents/workspace/mainsite_project/venv/lib/python3.7/site-packages/django/db/models/query.py", line 362, in aggregate
raise TypeError("Complex aggregates require an alias")
TypeError: Complex aggregates require an alias
Run Code Online (Sandbox Code Playgroud)
计算平均值的正确方法是什么?