Script# Unit tests with DOM access - unit-testing

I am trying to write unit test which suppose to access DOM, something simple like check if element exists.
I have created separte Test project, added QUnit for ASP.net MVC from Nuget and Script# Unit testing helpers. Added a reference to my Script# project.
I guess that I should run something like
WebTest web = new WebTest();
web.StartWebServer("/", 10258);
Uri testUri = web.GetTestUri("/Test.html");
WebTestResult ieResult = web.RunTest(testUri, WebBrowser.InternetExplorer);
web.StopWebServer();
But not sure where my Test.html should be and how I can run my [TestMethod] in the Test.html context. How I can dinamicaly create elements in Test.html?

Test.html should be a simple HTML file in your solution. Your test method is simply running IE and going to this page to run all the tests. You dynamically create new elements depending on how you layout the HTML.

See this sample (amongst others) at https://github.com/nikhilk/scriptsharp/tree/cc/samples/Photos/PhotoListTests
See the sample for how it sets up the root path for the server.
One thing to check for is that you've marked the build action for Test.html as Content so it gets copied over as part of building the test project.
Hope that helps.

Related

How to add unit tests to CKEditor custom plugins

I have made an initial custom plugin for CKEditor, but it's not obvious from the CKEditor documentation what is the best way to structure a custom plugin project or how to add unit tests.
I want to set up the project so that it follows good practices (like Test Driven Development) as I keep developing it, and possibly add it into a CI/CD pipeline.
Current setup
My custom plugin adds subject tags for the topic of a sentence.
I based it on the inline widget tutorial (which creates a Classic Editor v29 application with a local custom plugin added in) - https://ckeditor.com/docs/ckeditor5/latest/framework/guides/tutorials/implementing-an-inline-widget.html
|---app.js
|---index.html
|---node_modules/
|---package.json
|---subject/
|---|---subject.js
|---|---subjectcommand.js
|---|---subjectediting.js
|---|---subjectui.js
|---webpack.config.js
Test suite
The CKEditor Testing Environment documentation says that the #ckeditor/ckeditor5-dev-tests package can be used outside ckeditor5 - https://ckeditor.com/docs/ckeditor5/latest/framework/guides/contributing/testing-environment.html
So I rearranged the plugin directories to separate out src and tests:
|---app.js
|---index.html
|---node_modules/
|---package.json
|---subject/
|---|---src/
|---|---|---subject.js
|---|---|---subjectcommand.js
|---|---|---subjectediting.js
|---|---|---subjectui.js
|---|---tests/
|---|---|---subject.js
|---webpack.config.js
Then ran the test suite:
node ./node_modules/.bin/ckeditor5-dev-tests --files=*
But it looks like the ckeditor5-dev-tests package might only test plugins that are part of the CKEditor software (e.g. when you are contributing to the CKEditor project itself). All the --files option glob conversions map to node_modules/ckeditor5-* See: https://github.com/ckeditor/ckeditor5-dev/tree/master/packages/ckeditor5-dev-tests#rules-for-converting---files-option-to-glob-pattern
Question
I'm not sure if I'm using the testing suite wrong, or if I am taking the wrong approach in the project structure - maybe the project should just be for the plugin by itself (without app.js, etc.), then add it to the Classic Editor later somehow?

Testbox 2.1 - Skip an entire directory or CFC file

We want to create a HelperUtility.cfc with common methods for our tests to use. If we put the file in /tests/lib/HelperUtility.cfc, can we tell TestBox, don't try running any tests in /tests/lib? If not, can we add something to the component tag to skip the entire file, rather than adding skip to all the methods in the component individually?
There's no way to do that unfortunately.
I have tried to skip some manual mocks that were created inside a tests/mock folder, but you cannot configure TestBox at runtime to skip a specific folder if you decide to run the tests for a parent folder.
The only work around that worked for me was to create a specs subfolder in the parent tests and then call the testbox runner with a directory argument of the specs...
For example: http://localhost:8500/testbox/system/runners/HTMLRunner.cfm?directory=tests.specs

Unit testing Freemarker template

I have a Freemarker template that I would like to create a test for. The test renders the freemarker template using some mock information. I would like to render the template to an external file so that I can eyeball the results (make sure the html is aligned, etc).
I am using a traditional maven project structure for this project. Does anyone have any suggestions on what would be the most appropriate directory to output this temporary test file from my unit test?
I think you'd want to output it to somewhere underneath the maven ${basedir}/target directory. You can then clean it up as part of mvn clean.

How to make unit test in pyCharm

I want to make some unit tests, so I set up a list with values that all should be asserted true, just like this question. But I want it to run in PyCharm (With pressing Alt+Shift+F10)
If I just use the code from the answers, I just get No tests were found
You need to double check the settings for the tests run configuration:
By default PyCharm will inspect files that start with test and that are subclasses of unittest.TestCase, however you can control the Pattern and the subclasses option.
Change Pattern according to your test file names, it accepts Python regular expression.
Note that PyCharm will inspect only classes that inherit from unittest.TestCase so you should write the tests inside a class inherited from unittest.TestCase
PyCharm 2019.1+ and pytest
First, create a file named pytest.ini in order to set up custom configurations. For example, by default pytest will consider any file matching with test_*.py and *_test.py globs as a test module, so I encourage to have this file in order to define your custom file name patterns.
pytest.ini
[pytest]
python_files = test_*.py tests.py *_test.py
Now, open up the Run/Configuration window:
Add a new configuration, select Python tests and pytest:
In the following window you choose a name for your configuration, and you can also choose the target, but if you want pytest to use the pytest.ini file do not select Script path, APPLY, and OK.
Finally, run the test by clicking on the Play button.

How to use FireUnit to test my web page?

Can someone please tell me how can i test my web page in FireUnit?
http://ejohn.org/blog/fireunit/
I just played around with it last week and wrote a few test cases. You'll want to create a test case file and include it as part of your page. (perhaps use a conditional like "debug=true" to
prevent inclusion during production)
I found the .Compare method to be the most useful. You can write stuff like:
fireunit.compare(
"expected result",
callToFunction2(), // tested
"This is the test name"
);
Note that since you are comparing strings here, if you want to do JSON instead, you'll have to JSON.stringify the output first.
Upon running the page with the included js file, you'll see test results under the "Test" panel of firebug. (assuming you have the extension installed)