siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
1 lines • 11.2 kB
JavaScript
Ext.data.JsonP.structuring_test_suite({"guide":"<h1 id='structuring_test_suite-section-structuring-the-test-suite'>Structuring the test suite</h1>\n<div class='toc'>\n<p><strong>Contents</strong></p>\n<ol>\n<li><a href='#!/guide/structuring_test_suite-section-the-tree-of-sub-tests'>The tree of sub-tests</a></li>\n<li><a href='#!/guide/structuring_test_suite-section-isolation'>Isolation</a></li>\n<li><a href='#!/guide/structuring_test_suite-section-skipping'>Skipping</a></li>\n<li><a href='#!/guide/structuring_test_suite-section-expectations'>Expectations</a></li>\n<li><a href='#!/guide/structuring_test_suite-section-spies'>Spies</a></li>\n<li><a href='#!/guide/structuring_test_suite-section-buy-this-product'>Buy this product</a></li>\n<li><a href='#!/guide/structuring_test_suite-section-support'>Support</a></li>\n<li><a href='#!/guide/structuring_test_suite-section-see-also'>See also</a></li>\n<li><a href='#!/guide/structuring_test_suite-section-attribution'>Attribution</a></li>\n<li><a href='#!/guide/structuring_test_suite-section-copyright-and-license'>COPYRIGHT AND LICENSE</a></li>\n</ol>\n</div>\n\n<p>Siesta supports writing tests with BDD syntax. We recommend to look at BDD as just a way of structuring\nyour tests and not put extra ceremony in it. While it is possible to write your tests in the way,\nthat test suite will output a readable documentation for your system in the console, it is not the main goal.</p>\n\n<p>Main goal is to write coverage for the features your application have, to sort of \"freeze\" the spec in\ncertain state. That means we'll need to write and maintain a lot of tests, so one need to structure them\nsomehow. We found the following structuring scheme, to suite practical needs very well.</p>\n\n<h2 id='structuring_test_suite-section-the-tree-of-sub-tests'>The tree of sub-tests</h2>\n\n<p>A single test file can be organized as several nested sub-tests (in BDD terminology these are called \"specs\").\nTraditionally, <a href=\"#!/api/Siesta.Test.BDD-method-describe\" rel=\"Siesta.Test.BDD-method-describe\" class=\"docClass\">describe</a> is used to denote \"big\", top-level sections:</p>\n\n<pre><code>StartTest(t => {\n\n t.describe(\"My system\", t => {\n ...\n })\n})\n</code></pre>\n\n<p>And <a href=\"#!/api/Siesta.Test-method-it\" rel=\"Siesta.Test-method-it\" class=\"docClass\">it</a> is used to denote tests for smaller, more specific functionality.</p>\n\n<pre><code>StartTest(t => {\n t.describe(\"My system\", t => {\n\n t.it(\"Should allow user to log in\", t => {\n ...\n })\n })\n})\n</code></pre>\n\n<p>The difference between <code>describe</code> and <code>it</code> is pure semantically - codewise they are the same, both are just sub tests,\nforming a tree, with the top-level test file as the root. Sub tests can be nested arbitrarily, <code>it</code> section can contain <code>describe</code>\nand vice-versa.</p>\n\n<p>Every sub test receives a new <a href=\"#!/api/Siesta.Test\" rel=\"Siesta.Test\" class=\"docClass\">Siesta.Test</a> instance as the 1st argument, which should be used inside the test.</p>\n\n<p>See also getSubTest method.</p>\n\n<h2 id='structuring_test_suite-section-isolation'>Isolation</h2>\n\n<p>Best practice will be to make every section standalone, somewhat limited and not depending on others. Then you have a lot of small such sections.\nThis makes the test more readable and limits the scope of every testing scenario.</p>\n\n<p>We found, that readability of tests is optimal, when nesting is not more than 2-3 levels. If you need more levels, then may be its a good idea\nto start a new test file instead. You may need to make some functionality re-usable,\nby <a href=\"#!/guide/extending_test_class\">extending the Siesta.Test class</a>.</p>\n\n<p>You can use <a href=\"#!/api/Siesta.Test-method-beforeEach\" rel=\"Siesta.Test-method-beforeEach\" class=\"docClass\">beforeEach</a>/<a href=\"#!/api/Siesta.Test-method-afterEach\" rel=\"Siesta.Test-method-afterEach\" class=\"docClass\">afterEach</a> methods to add\ncommon setup/cleanup code. Overall, usually it looks like this:</p>\n\n<pre><code>StartTest(t => {\n // global variable accessed by all subtests\n let store\n\n t.beforeEach(function () {\n // do setup, return some fixed dataset for example:\n store = new DataStore({ data : [ { foo : 'bar'} ] })\n })\n\n t.it(\"Should fire load event\", t => {\n store.load()\n\n // `store` instance will be \"fresh\" not shared with others \"it\" sections\n t.firesOk(store, \"load\", 1, \"Exactly one load event fired\")\n ...\n })\n\n t.it(\"Should sort correctly\", t => {\n // again `store` here will be newly created instance\n store.sort()\n\n // verify sorting\n ...\n })\n})\n</code></pre>\n\n<p>In the \"beforeEach\" function you can also for example render some components or do something else (like clear the DB).</p>\n\n<p>Sometimes the \"beforeEach\" function has to be async:</p>\n\n<pre><code>StartTest(t => {\n var store\n\n // declare the `beforeEach` with 2 arguments, 2nd is the callback\n t.beforeEach((t, next) => {\n store = new DataStore({ data : [ { foo : 'bar'} ] })\n\n // call the provided `next` callback when the `beforeEach` action has completed\n // in this case it is asyncronous store loading\n store.load({ callback : next })\n })\n\n t.it(\"Should do this\", t => {\n // `store` instance will be already loaded\n t.expect(store.getCount()).toBeGreaterThan(0)\n })\n\n t.it(\"Should do that\", t => {\n // `store` instance will be already loaded\n ...\n })\n})\n</code></pre>\n\n<h2 id='structuring_test_suite-section-skipping'>Skipping</h2>\n\n<p>You can also easily test just one sub-test by adding the extra letter in the beginning: <a href=\"#!/api/Siesta.Test-method-iit\" rel=\"Siesta.Test-method-iit\" class=\"docClass\">iit</a>,\n<a href=\"#!/api/Siesta.Test-method-ddescribe\" rel=\"Siesta.Test-method-ddescribe\" class=\"docClass\">ddescribe</a>) or exclude some sub-test (<a href=\"#!/api/Siesta.Test-method-xit\" rel=\"Siesta.Test-method-xit\" class=\"docClass\">xit</a>, <a href=\"#!/api/Siesta.Test-method-xdescribe\" rel=\"Siesta.Test-method-xdescribe\" class=\"docClass\">xdescribe</a>).</p>\n\n<p>See also failOnExclusiveSpecsWhenAutomated method.</p>\n\n<h2 id='structuring_test_suite-section-expectations'>Expectations</h2>\n\n<p>Assertions in BDD terminilogy are called <em>expectations</em>.</p>\n\n<p class=\"side-note\">\nSiesta supports the expectations syntax as described below. We found it less self-explanatory though, as failed assertions \nlack any context and sometimes its harder to find, what exactly has failed. You can use any of the assertions styles,\nor mix both.\n</p>\n\n\n<p></p>\n\n<p>Expectation can be created with the <a href=\"#!/api/Siesta.Test.BDD-method-expect\" rel=\"Siesta.Test.BDD-method-expect\" class=\"docClass\">expect</a> method.</p>\n\n<pre><code>StartTest(t => {\n t.describe(\"My system\", t => {\n t.it(\"Should allow user to log in\", t => {\n t.expect(MyApp.LoginManager.isLoggedIn()).toBe(false)\n\n MyApp.LoginManager.login()\n\n t.expect(MyApp.LoginManager.isLoggedIn()).toBe(true)\n })\n\n t.describe(\"Report engine of my system\", t => {\n t.it(\"Should allow generate reports in PDF\", t => {\n ...\n })\n })\n })\n})\n</code></pre>\n\n<p>Please refer to the <a href=\"#!/api/Siesta.Test.BDD.Expectation\" rel=\"Siesta.Test.BDD.Expectation\" class=\"docClass\">Siesta.Test.BDD.Expectation</a> for the list of supported expectations.</p>\n\n<h2 id='structuring_test_suite-section-spies'>Spies</h2>\n\n<p>Siesta implements spies with the same functionality and syntax as seen in Jasmine along with small improvements.\nOne can spy on a function property of some object or create a standalone spy, suitable for event listener or similar.</p>\n\n<pre><code>StartTest(t => {\n ...\n\n let spy = t.spyOn(obj, 'process')\n // or, if you need to call the original 'process' method\n let spy = t.spyOn(obj, 'process').and.callThrough()\n\n // call the method\n obj.process('fast', 1)\n\n t.expect(spy).toHaveBeenCalled();\n t.expect(spy).toHaveBeenCalledWith('fast', 1);\n})\n</code></pre>\n\n<p>Please refer to the <a href=\"#!/api/Siesta.Test.BDD-method-spyOn\" rel=\"Siesta.Test.BDD-method-spyOn\" class=\"docClass\">Siesta.Test.BDD.spyOn</a> method and <a href=\"#!/api/Siesta.Test.BDD.Spy\" rel=\"Siesta.Test.BDD.Spy\" class=\"docClass\">Siesta.Test.BDD.Spy</a> class.</p>\n\n<h2 id='structuring_test_suite-section-buy-this-product'>Buy this product</h2>\n\n<p>Visit our store: <a href=\"https://bryntum.com/store/siesta\">https://bryntum.com/store/siesta</a></p>\n\n<h2 id='structuring_test_suite-section-support'>Support</h2>\n\n<p>Ask a question in our community forum: <a href=\"https://www.bryntum.com/forum/viewforum.php?f=20\">https://www.bryntum.com/forum/viewforum.php?f=20</a></p>\n\n<p>Subscribers can post expedited questions in Premium Forum: <a href=\"https://www.bryntum.com/forum/viewforum.php?f=21\">https://www.bryntum.com/forum/viewforum.php?f=21</a></p>\n\n<p>Please report any bugs through the web interface at <a href=\"https://www.assembla.com/spaces/bryntum/support/tickets\">https://www.assembla.com/spaces/bryntum/support/tickets</a></p>\n\n<h2 id='structuring_test_suite-section-see-also'>See also</h2>\n\n<p>Siesta web-page: <a href=\"https://bryntum.com/products/siesta\">https://bryntum.com/products/siesta</a></p>\n\n<p>Other Bryntum products: <a href=\"https://bryntum.com/products\">https://bryntum.com/products</a></p>\n\n<h2 id='structuring_test_suite-section-attribution'>Attribution</h2>\n\n<p>This software contains icons from the following icon packs (licensed under Creative Common 2.5/3.0 Attribution licenses)</p>\n\n<ul>\n<li><a href=\"http://www.famfamfam.com/lab/icons/silk/\">http://www.famfamfam.com/lab/icons/silk/</a></li>\n<li><a href=\"http://led24.de/iconset/\">http://led24.de/iconset/</a></li>\n<li><a href=\"http://p.yusukekamiyamane.com/\">http://p.yusukekamiyamane.com/</a></li>\n<li><a href=\"http://rrze-icon-set.berlios.de/index.html\">http://rrze-icon-set.berlios.de/index.html</a></li>\n<li><a href=\"http://www.smashingmagazine.com/2009/05/20/flavour-extended-the-ultimate-icon-set-for-web-designers/\">http://www.smashingmagazine.com/2009/05/20/flavour-extended-the-ultimate-icon-set-for-web-designers/</a></li>\n<li><a href=\"http://www.doublejdesign.co.uk/products-page/icons/super-mono-icons/\">http://www.doublejdesign.co.uk/products-page/icons/super-mono-icons/</a></li>\n<li><a href=\"http://pixel-mixer.com/\">http://pixel-mixer.com/</a></li>\n</ul>\n\n\n<p>Thanks a lot to the authors of the respective icons packs.</p>\n\n<h2 id='structuring_test_suite-section-copyright-and-license'>COPYRIGHT AND LICENSE</h2>\n\n<p>Copyright (c) 2009-2022, Bryntum & Nickolay Platonov</p>\n\n<p>All rights reserved.</p>\n","title":"Structuring the test suite"});