现在可以使用Scala 2.9.0 RC3以及描述该版本中添加的强大功能的发布页面,是否有人知道我们在2.10和未来版本中可以期待什么?
在Java 8中,使用以下类
class Person {
private boolean born;
Person() {
}
public void setBornTrue() {
born = true;
}
public void setBorn(boolean state) {
born = state;
}
}
Run Code Online (Sandbox Code Playgroud)
可以通过方法引用调用setBornTrue方法:
ArrayList<Person> people = new ArrayList<>();
people.add(new Person());
people.forEach(Person::setBornTrue);
Run Code Online (Sandbox Code Playgroud)
但是我如何使用forEach方法并使用方法引用来使用setBorn ?试:
people.forEach(Person::setBorn);
Run Code Online (Sandbox Code Playgroud)
导致错误,"无法解析方法setBorn".
另外,我如何传递True的值?
关于弃用环回测试的谷歌小组发布的帖子中有一个问题,即提供一个如何在没有环回测试的情况下实现测试的正确示例.该线程谈论使用supertest而不是.
下面是我尝试将Mocha,supertest和模型(来自app.js)结合起来.当我自己运行文件时,结果非常好.但是如果我有另一个测试文件(比如test-teacher.js)那么第一个测试文件(称为test-student.js)就会以奇怪的方式开始失败,我无法描述.
我错过了什么或者可以使用不能使用的模型,就像我在下面使用它们一样?
describe('/Student', function () {
var server = require('../server/server')
var loopback = require('loopback')
var supertest = require('supertest')
var request = require('supertest')(server)
var dataSource = server.dataSource('db', {adapter: 'memory'})
var Student = dataSource.define('Student', {
'id': Number,
'points': Number
});
beforeEach(function () {
Student.updateOrCreate({id: 1, points: 5000});
})
it('Post a new student', function (done) {
request.post('/api/Students').send({points: 5000}).expect(200, done)
})
})
Run Code Online (Sandbox Code Playgroud) 在以下示例中:
Execution execution = mock(Execution.class);
when(execution.getLastQty()).thenReturn(1000.0);
when(execution.getLastPrice()).thenReturn(75.0);
order.onFillReceived(execution);
assertEquals(0, order.getLeavesQty(), 0);
Run Code Online (Sandbox Code Playgroud)
执行还有许多其他不应该被调用的方法.在此测试中只应使用已经模拟的两种方法,并且应该调用它们.如果调用任何其他方法,则测试应该失败.
如果调用任何其他方法,如何告诉Mockito失败?
我完全把Scala作为一种语言...而且我仍然为什么任何公司应该使用Scala而不是Java而苦苦挣扎.Scala是否只是JVM之上的合成糖,还是Scala over Java的基本改进可以改善现实世界的应用程序?
java ×3
scala ×2
lambda ×1
loopbackjs ×1
mocha.js ×1
mockito ×1
node.js ×1
roadmap ×1
supertest ×1
unit-testing ×1