使用Jasmine测试Java Script应用程序

Testing Java Script app using Jasmine

本文关键字:Script 应用程序 Java 测试 Jasmine 使用      更新时间:2023-09-26

我使用Sencha Architect构建了一个应用程序,并计划使用Jasmine进行测试。我是Sencha Architect和Jasmine的新手。为了让我测试应用程序,我需要在我的HTML索引文件中添加ExtJS库/CSS吗?我已经在我的HTML索引文件中添加了所有Jasmine框架的CSS和JS文件以及Jasmine测试用例文件。

谢谢。

我将指导您通过使用Sencha Cmd 5的工作测试的快速设置。, ExtJs,并期望您使用Sencha工作区只需8步。

  1. 首先使用Sencha Cmd创建一个新的工作空间。如果你已经有了一个工作空间,你可以跳过这一步。

    sencha generate workspace 'path'to'the'folder

  2. 使用Sencha Cmd创建一个新的ExtJs应用。

    cd 'path'to'the'workspace sencha -sdk 'path'to'the'sdk generate app Jasmine jasmine

  3. 然后在app文件夹中新建一个名为app-test的文件夹

  4. 下载独立版本的Jasmine
  5. 解压缩并将lib文件夹复制到之前创建的app-test文件夹中。
  6. 创建一个html文件index-test.html,并把它放在你的app文件夹:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Jasmine Test</title>
	<link rel="shortcut icon" type="image/png" href="app-test/lib/jasmine-2.3.4/jasmine_favicon.png">
	<link rel="stylesheet" href="app-test/lib/jasmine-2.3.4/jasmine.css">
	<script src="app-test/lib/jasmine-2.3.4/jasmine.js"></script>
	<script src="app-test/lib/jasmine-2.3.4/jasmine-html.js"></script>
	<script src="app-test/lib/jasmine-2.3.4/boot.js"></script>
	<!-- include source files here... -->
	<script src="../ext/build/ext-all-debug.js"></script>
	<!-- include spec files here... -->
	<script src="app-test.js"></script>
</head>
<body>
	<div id="test"></div>
</body>
</html>

  • 创建一个javascript文件app-test.js,并把它放在你的app文件夹:
  • Ext.Loader.setConfig({
        enabled: true
    });
    Ext.application({
    	name: 'Jasmine',
    	extend: 'Jasmine.Application',
    	autoCreateViewport: false
    });
    describe('Jasmine.view.main.Main', function() {
    	//reusable scoped variable
    	var mainView = null;
    	// setup / teardown
    	beforeEach(function() {
    		// create a fresh main view for every test to avoid test pollution
    		mainView = Ext.create('Jasmine.view.main.Main'/*, {
    			renderTo : 'test' //see index-test.html to see where this is defined
    		}*/);
    	});
    	afterEach(function() {
    		// destroy the main view after every test so we don't pollute the environment
    		mainView.destroy();
    	});
    	it('should inherit from Ext.container.Container', function() {
    		expect(mainView.isXType('container')).toEqual(true);
    	});
    	it('should be configured as a border layout', function() {
    		expect(mainView.getLayout().type).toEqual('border');
    	});
    });

    在浏览器中打开index-test.html并查看结果额外资源:

    <我>
    http://www.ladysign-apps.com/developer/setup-jasmine-tdd-with-for-ext-js/
    https://www.sencha.com/blog/automating-unit-tests/
    https://github.com/SenchaProSvcs/UnitTestDemo
    http://docs.sencha.com/extjs/4.2.0/!/指导/测试
    http://docs.sencha.com/extjs/4.2.0/!/指导/testing_controllers
    https://jasmine.github.io/2.3/introduction.html