[英]How to implement testing on a project using java dynamic web project, and Angularjs
I'm new to angularjs and I want to implement testing into the project. 我是angularjs的新手,我想在项目中实施测试。
Currently my app: 目前我的应用程式:
Backend : Java as a REST API 后端 :将Java作为REST API
Frontend : Angularjs consuming the api. 前端 :使用api的Angularjs。
My project runs on a tomcat server, and most of the testing frameworks for angularjs is on node.js. 我的项目在tomcat服务器上运行,并且angularjs的大多数测试框架都在node.js上。 Is there a way for me to test the angularjs with the current setup?
我有没有办法用当前设置测试angularjs? I don't want to install node.js, as it get more complicated for me.
我不想安装node.js,因为它对我来说变得更加复杂。
Here is my project structure: 这是我的项目结构:
I was able to implement Jasmine standalone testing, you do not need nodejs. 我能够实现Jasmine独立测试,您不需要nodejs。 However to execute the tests, we need to refresh the page constantly, i'm currently looking for a way to automate that.
但是,要执行测试,我们需要不断刷新页面,我目前正在寻找一种自动化的方法。
test.html 的test.html
<html>
<head>
<meta charset="ISO-8859-1">
<link rel="shortcut icon" type="image/png" href="test/jasmine/lib/jasmine-2.6.4/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="test/jasmine/lib/jasmine-2.6.4/jasmine.css">
<script type="text/javascript" src="test/jasmine/lib/jasmine-2.6.4/jasmine.js"></script>
<script type="text/javascript" src="test/jasmine/lib/jasmine-2.6.4/jasmine-html.js"></script>
<script type="text/javascript" src="test/jasmine/lib/jasmine-2.6.4/boot.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script>
<script type="text/javascript" src="https://code.angularjs.org/1.6.2/angular-mocks.js"></script>
<script src="js/jquery.min.js"></script>
<!-- Angular Code -->
<script type="text/javascript" src="js/app.js"></script>
<!-- Unit Testing Code -->
<script type="text/javascript" src="test/test.js"></script>
</head>
</html>
In test.js, a sample test case. 在test.js中,是一个示例测试用例。
describe('Test', function (){
beforeEach(module('myApp'));
var $controller;
beforeEach(inject(function(_$controller_, _$httpBackend_){
$controller = _$controller_;
$httpBackend =_$httpBackend_;
$scope = {};
}));
/*makeURLParameters*/
it('Testing [fController]: : makeURLParameters 1, default', function(){
var controller = $controller('fController', { $scope: $scope });
expect($scope.makeURLParameters()).toEqual("?page=0&size=15&sort=code&order=asc");
});
});
Then in a browser, open the test.html file and it will run the test cases. 然后在浏览器中,打开test.html文件,它将运行测试用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.