我正在寻找使用Spring设置单元和集成测试的最佳实践.
我通常使用3种测试:
目前我只有第二类测试,这是棘手的部分.我设置了一个基础测试类,如:
@ContextConfiguration(locations = { "/my_spring_test.xml" })
public abstract class AbstractMyTestCase extends AbstractJUnit4SpringContextTests
Run Code Online (Sandbox Code Playgroud)
而"单位"测试如下:
public class FooTest extends AbstractMyTestCase
Run Code Online (Sandbox Code Playgroud)
使用自动装配的属性.
在不同(集成测试)环境中运行测试的最佳方法是什么?对测试进行子类化并覆盖ContextConfiguration?
@ContextConfiguration(locations = { "/my_spring_integration_test.xml" })
public class FooIntegrationTest extends FooTest
Run Code Online (Sandbox Code Playgroud)
这会有用吗(我目前无法在这里轻松测试)?这种方法的问题是"@ContextConfiguration(locations = {"/ my_spring_integration_test.xml"})"重复了很多.
有什么建议?
此致,弗洛里安
以下JAXB绑定文件按预期创建Adapter类,但Eclipse和XMLSpy说它无效:
<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" version="2.1">
<jxb:globalBindings>
<jxb:javaType name="java.util.Calendar" xmlType="xs:date" parseMethod="javax.xml.bind.DatatypeConverter.parseDate"
printMethod="javax.xml.bind.DatatypeConverter.printDate" />
<jxb:javaType name="java.util.Calendar" xmlType="xs:dateTime" parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />
<jxb:javaType name="java.util.Calendar" xmlType="xs:time" parseMethod="javax.xml.bind.DatatypeConverter.parseTime"
printMethod="javax.xml.bind.DatatypeConverter.printTime" />
</jxb:globalBindings>
</jxb:bindings>
Run Code Online (Sandbox Code Playgroud)
错误是这样的:
cvc-complex-type.2.4.b: The content of element 'jxb:globalBindings' is not complete. One of '{"http://java.sun.com/xml/ns/jaxb":javaType, "http://java.sun.com/xml/ns/jaxb":serializable, WC[##other:"http://java.sun.com/xml/ns/jaxb"]}' is expected.
Run Code Online (Sandbox Code Playgroud)
请注意,JAXB绑定模式文件使用前缀"jaxb"引用顶级元素.
如何创建有效的JAXB绑定文件?
我正在构建一个OSGI基础应用程序,在我的一个类中我执行了大量的导入(大约30个),当我启动应用程序时,我得到了这个异常:
java.lang.ArrayIndexOutOfBoundsException: 18
at aQute.lib.osgi.Clazz.parseClassFile(Clazz.java:130)
at aQute.lib.osgi.Clazz.<init>(Clazz.java:65)
at aQute.lib.osgi.Processor.analyzeJar(Processor.java:159)
at aQute.lib.osgi.Processor.analyzeBundleClasspath(Processor.java:77)
at aQute.lib.osgi.Analyzer.analyze(Analyzer.java:194)
at aQute.lib.osgi.Builder.analyze(Builder.java:95)
at aQute.lib.osgi.Analyzer.calcManifest(Analyzer.java:293)
at aQute.lib.osgi.Builder.build(Builder.java:45)
at org.apache.felix.bundleplugin.BundlePlugin.buildOSGiBundle(BundlePlug...
Run Code Online (Sandbox Code Playgroud)
当我评论代码并减少进口数量一切顺利.
这似乎是一个OSGI限制,我该如何解决这个问题呢?
谢谢,
当通过GitHub的Web界面执行操作(例如合并pull请求或处理gh-pages)时,提交的作者是:
real name <email@address>
Run Code Online (Sandbox Code Playgroud)
但我希望它是
user name <email@address>
Run Code Online (Sandbox Code Playgroud)
有没有办法改变这个?
在我的本地仓库工作并从这里推送时,一切都如预期.
编辑
以下是重现此问题的一些简单步骤:
这是一个测试仓库(稍后我将删除它):https://github.com/puce77/test
编辑2
或者是否建议使用真实姓名?是什么原因?我认为用户名是唯一的,但真实姓名可能不是.实名也比用户名更有可能(例如婚姻).
在我的单元测试中,我自动安装了一些使用URL的DataSources
jdbc:derby:memory:mydb;create=true
Run Code Online (Sandbox Code Playgroud)
创建内存中的DB.
要删除内存中的Derby数据库,您必须连接:
jdbc:derby:memory:mydb;drop=true
Run Code Online (Sandbox Code Playgroud)
我想在每次测试后都会发生这种情况,并从一个新的数据库开始.我怎么能用Spring做到这一点?
我想使用Maven-Release-Plugin发布我的项目的新版本.
但是我收到以下错误:
[INFO] Tagging release with the label softsmithy-lib-v0.1...
[INFO] EXECUTING: /bin/sh -c cd /var/lib/hudson/jobs/SoftSmithy-Utility-Library-Release && hg tag --message '[maven-release-plugin] copy for tag softsmithy-lib-v0.1' softsmithy-lib-v0.1
[ERROR]
EXECUTION FAILED
Execution of cmd : tag failed with exit code: 255.
Working directory was:
/var/lib/hudson/jobs/SoftSmithy-Utility-Library-Release
Your Hg installation seems to be valid and complete.
Hg version: 1.7.5 (OK)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An error is occurred in the tag process: Exception while executing SCM command.
Error while executing command …Run Code Online (Sandbox Code Playgroud) 在 Spring Boot 应用程序中,我想测试(JUnit 5)启用审计(@EnableJpaAuditing)的持久层。我使用 Liquibase 设置 H2 数据库和 Hibernate 作为 JPA 实现。
@Configuration
//@EnableTransactionManagement
@EnableJpaAuditing
//@EnableJpaRepositories
public class MyPersistenceConfig {
}
Run Code Online (Sandbox Code Playgroud)
我的实体有以下字段:
@CreatedDate
@Column(name = "CREATED_AT", updatable = false)
private Instant createdAt;
@CreatedBy
@Column(name = "CREATED_BY", updatable = false)
private String createdBy;
@CreatedDate
@Column(name = "LAST_MODIFIED_AT")
private Instant lastModifiedAt;
@CreatedBy
@Column(name = "LAST_MODIFIED_BY")
private String lastModifiedBy;
Run Code Online (Sandbox Code Playgroud)
我有以下依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<scope>runtime</scope>
<!--<scope>test</scope>-->
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency> …Run Code Online (Sandbox Code Playgroud) java spring-security spring-test spring-data-jpa spring-boot
我们如何提供带有 Java 11 模块的注释处理器?
要注册注释提供程序,我们需要以下模块信息条目:
import javax.annotation.processing.Processor;
import com.mycompany.mylib.impl.MyAnnotationProcessor;
module com.mycompany.mylib {
provides Processor with MyAnnotationProcessor;
}
Run Code Online (Sandbox Code Playgroud)
现在,不幸的是,这是不是因为包装不够javax.annotation.processing,javax.lang.model.*而javax.tools不是在java.base模块,但在java.compiler模块。
在 Java SE 8 中,一切都只在 JRE 中可用,但在 Java 11 中,我们可以选择只使用一个子集。随着jlink我们再可以创建更小的运行时间图像。
现在,当然,我可以将以下内容添加到模块信息中:
requires java.compiler;
Run Code Online (Sandbox Code Playgroud)
但这也会导致java.compiler成为自定义运行时映像的一部分。
但是注解处理有些特殊:它是在编译时运行的代码,而不是在运行时运行。因此它不应该是运行时映像的一部分。它应该只是编译时要求/依赖项。
有没有办法用 Java 11 模块系统解决这个问题?
看来太阳网址终于破了:http://bugs.sun.com/
虽然它仍然提到:
http://www.oracle.com/technetwork/java/javase/community/index.html
我仍然可以在以下网址提交错误:http://bugreport.sun.com/bugreport/
但即使是邮件中的链接也提到:http://bugs.sun.com/
有没有人找到新的链接?
更新使用此链接:https://bugs.openjdk.java.net/ - 保留错误号码!
我有一个如下的XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="1.0">
<xs:element name="foo">
<xs:complexType>
<xs:sequence>
<xs:element name="bar">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="a"/>
<xs:enumeration value="b"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="subtype" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="aa"/>
<xs:enumeration value="bb"/>
<xs:enumeration value="cc"/>
<xs:enumeration value="dd"/>
<xs:enumeration value="ee"/>
<xs:enumeration value="ff"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="something">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
但JAXB不生成枚举:
@XmlAttribute(name = "type", required = true)
protected String type;
@XmlAttribute(name = "subtype", required …Run Code Online (Sandbox Code Playgroud) java ×8
jaxb ×2
spring ×2
xsd ×2
derby ×1
github ×1
import ×1
junit ×1
maven ×1
maven-2 ×1
mercurial ×1
module-info ×1
osgi ×1
spring-boot ×1
spring-test ×1
unit-testing ×1