当使用Eclipse JUnit和gradle test运行单元测试时,我得到不同的结果。上一堂课:
updateForm
和类似的测试(将案例压缩到一个测试以节省空间)
runtime: nodejs8
env: standard
instance_class: B1
handlers:
- url: '.*'
script: index.js
basic_scaling:
idle_timeout: 900s
max_instances: 1
一切都按预期进行。
然后,拥有一个像这样的课程:
@Getter @Setter
@EqualsAndHashCode
public class ObjectWithId {
private Long id;
}
使用类似的测试
@Test
public void testObjectWithId() {
ObjectWithId o1 = new ObjectWithId(), o2 = new ObjectWithId();
o1.setId(1L);
o2.setId(1L);
assertEquals(o1.hashCode(), o2.hashCode());
assertEquals(o1, o2);
o2.setId(2L);
assertNotEquals(o1, o2);
assertNotEquals(o1.hashCode(), o2.hashCode());
}
在使用Eclipse JUnit运行时失败,但通过gradle测试成功吗?我从Eclipse和命令行运行gradle test,没有区别。因此,似乎gradle以某种方式更了解应如何对待@Getter @Setter
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class ObjectWithIdAndDate {
@EqualsAndHashCode.Include
private Long id;
private LocalDateTime created;
}
...?
我的@Test
public void testObjectWithIdAndDate() {
ObjectWithIdAndDate o1 = new ObjectWithIdAndDate(), o2 = new ObjectWithIdAndDate();
o1.setId(1L);
o2.setId(1L);
assertEquals(o1.hashCode(), o2.hashCode());
assertEquals(o1, o2);
o2.setId(2L);
assertNotEquals(o1, o2);
assertNotEquals(o1.hashCode(), o2.hashCode());
o2.setId(1L);
o2.setCreated(LocalDateTime.now());
// Eclipse JUnit starts failing here because setting the created.
// Gradle test will pass.
assertEquals(o1.hashCode(), o2.hashCode());
assertEquals(o1, o2);
o1.setCreated(LocalDateTime.now());
assertEquals(o1.hashCode(), o2.hashCode());
assertEquals(o1, o2);
}
中有@EqualsAndHashCode(onlyExplicitlyIncluded = true)
,并且在Eclipse中安装了相同版本的lombok.jar。
gradle项目和Eclipse都使用JUnit版本4.12。我在这里想念什么?
一些进一步的调查:
我用Maven构建了其他相同的项目。令我惊讶的是,该项目也通过了JUnit测试。
这听起来像是Eclipse gradle项目方面或某些其他gradle项目特定设置有问题吗?
答案 0 :(得分:2)
您还需要更新Eclipse的lombok安装。您可以在“帮助”>“关于Eclipse”屏幕中验证安装的版本。在白色区域,底行应告知您已安装的版本。
运行java -jar lombok.jar
来更新您的安装。