当我运行SpecRunner HTML文件时,我收到此错误.
环顾四周,这是由于angular-mocks.js
没有被引用.在我的情况下,它被引用.
SpecRunner.html:
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>
<script type="text/javascript" src="lib/angular-mocks.js"></script>
<!-- include source files here... -->
<script type="text/javascript" src="../main/static/js/controllers/norm-definitions-controller.js"></script>
Run Code Online (Sandbox Code Playgroud)
运行测试时,我得到以下异常: ReferenceError: inject is not defined
我可以看到它angular-mocks.js
被引用,它不是缓存问题,因为我可以使用Firebug看到它.
看着angular-mocks.js
我可以看到完整的参考angular.mock.inject = function() { ... }
,我也尝试过这个作为参考,并得到例外ReferenceError: angular is not defined
.
美好的一天.以下代码:
class A{
private B b;
@Transactional
public SomeResult doSomething(){
SomeResult res = null;
try {
// do something
} catch (Exception e) {
res = b.saveResult();
}
return res ;
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
class B{
public SomeResult saveResult(){
// save in db
}
}
Run Code Online (Sandbox Code Playgroud)
据我了解,如果方法中存在异常,doSomething
则不会回滚事务.以及如何使其滚动?并返回了SomeResult
我正在尝试对自定义进行单元测试ConfigurationElementCollection
,但是我遇到了以编程方式填充集合的问题.当我打电话时BaseAdd()
,我得到以下异常:
ConfigurationErrorsException:元素"add"已被锁定在更高级别的配置中.
但是,此问题仅在运行多个测试时出现.考虑这两个测试:
private Fixture Fixtures = new Fixture(); // AutoFixtures
[Test]
public void test1()
{
var tc = Fixtures.CreateAnonymous<TenantCollection>();
var t = Fixtures.CreateAnonymous<Tenant>();
tc.Add(t);
}
[Test]
public void test2()
{
var tc = Fixtures.CreateAnonymous<TenantCollection>();
var t = Fixtures.CreateAnonymous<Tenant>();
tc.Add(t);
}
Run Code Online (Sandbox Code Playgroud)
单独执行时,每个单独的测试通过.一起运行时,抛出锁定异常.
这里发生了什么?如何解锁集合或解决锁定问题?
我正在尝试为我的应用创建一个"喜欢"的功能.我希望能够将动态生成的数字的值设置为"like count".问题在于使用'ng-init',因为文档说这是一个不好的方法!
如何在"控制器"中设置值而不是"视图"?
这是我到目前为止:
<!doctype html>
<html ng-app="plunker" >
<head>
<meta charset="utf-8">
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<article ng-repeat="feed in feeds">
<h3>{{feed.createdby}}</h3>
<p>{{feed.content}}</p>
<button ng-click="likeClicked($index)">{{isLiked[$index]|liked}}</button>
<span ng-init="likeCount=feed.likes.length">{{likeCount}}</span>
</article>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
谢谢,
J.P
我有一个包含公共方法的类,它依赖于内部方法以正确返回其值.
让我们考虑以下类和测试文件:
public class ClassUnderTest
{
public string NotMockedPublicMethod()
{
return MockedMethod();
}
virtual public string MockedMethod()
{
return "original";
}
}
Run Code Online (Sandbox Code Playgroud)
以下测试用例可行:
var mock = new Mock<ClassUnderTest> { CallBase = true };
mock.Setup(m => m.MockedMethod()).Returns("mocked");
Assert.AreEqual("mocked", mock.Object.NotMockedPublicMethod());
Run Code Online (Sandbox Code Playgroud)
但是,让我们说我的这个MockedMethod()
在外部没有效用.问题是将此方法标记为internal
(即使使用InternalsVisibleTo()
正确):
virtual internal string MockedMethod()
Run Code Online (Sandbox Code Playgroud)
将使完全相同的测试失败并显示消息Assert.AreEqual failed. Expected:<mocked>. Actual:<original>
.
这是Moq的bug还是有些限制?
我从包含逗号的cookie获取值时遇到问题.它不返回完整的字符串,但字符串被截断为第一个逗号.例如:
// cookie value = var1,var2,var3
String cookieVal = cookie.getValue();
//cookieVal now is "var1" instead of "var1,var2,var3"
Run Code Online (Sandbox Code Playgroud)
和
// cookie value = var1=var2=var3
String cookieVal = cookie.getValue();
//cookieVal now is "var1=var2=var3"
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么.
$resource
这里有一个简化的例子(改编自Angular网站):
angular.module('project', ['mongolab']);
function ListCtrl($scope, Project) {
$scope.projects = Project.test();
}
angular.module('mongolab', ['ngResource']).
factory('Project', function ($resource) {
var url, dfParams, actions;
url = 'https://api.mongolab.com/api/1/databases' + '/angularjs/collections/projects/:id';
dfParams = {
apiKey: '4f847ad3e4b08a2eed5f3b54'
};
actions = {
test: {
method: 'GET',
isArray: true,
transformResponse: function (response) {
// line is never getting called
console.log('transforming');
return response;
}
};
var Project = $resource(url, dfParams, actions);
return Project;
});
Run Code Online (Sandbox Code Playgroud)
问题是线路console.log('transforming')
永远不会被调用.这是为什么?其他一切都很好.
活在这里小提琴.
我目前正在试验AngularJS.我创建了一个简单的服务,它是从一些远程数据初始化的.url作为应用程序值传递.
//App declaration
angular.module('myApp', ['myApp.services']).value('someUrl', 'http://www.example.com');
//Service declaration
angular.module('myApp.services', ['someUrl']).factory('MyService', function(someUrl) {
var data;
"Do stuff"
return data;
});
Run Code Online (Sandbox Code Playgroud)
现在,我正在尝试对此进行单元测试,但我无法正确设置"someUrl"参数.我尝试过这样的事情,没有成功:
angular.module('myApp', ['myApp.services']).value('someUrl', 'test/test.json');
describe('Services', function() {
beforeEach(module('myApp.services'));
describe('MyService', function() {
it('should return {success: true}', inject(function() {
expect(data).toEqual({success: true});
}));
});
});
Run Code Online (Sandbox Code Playgroud)
但是,我总是收到"No module:someUrl"错误.在单元测试期间初始化app值的正确语法是什么?
我抓住了Angular Seed项目并修改了它的场景测试.我正在尝试一个非常简单的测试,所以我相信这是我所缺少的.这是DSL和Scenario规范:
angular.scenario.dsl('customDsl', function() {
return function(selector) {
return this.addFutureAction('customDsl', function ($window, $document, done) {
done(null, selector + ' is ok!');
});
};
});
describe('my app', function() {
it('should pass', function() {
expect(customDsl('test')).toBe('test is ok!');
});
});
Run Code Online (Sandbox Code Playgroud)
运行测试时,它失败并显示以下消息:
Frame window is not accessible.
Run Code Online (Sandbox Code Playgroud)
我正在使用Windows 7并在Chrome中运行方案.要运行测试,我启动服务器node scripts\web-server.js
,然后scripts\e2e-test.bat
.
angularjs ×6
unit-testing ×3
java ×2
javascript ×2
.net ×1
app-config ×1
c# ×1
cookies ×1
hibernate ×1
jasmine ×1
mocking ×1
moq ×1
scope ×1
spring ×1
transactions ×1