Unit testing Freemarker template - unit-testing

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.

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

What is the best way to "compile" HTML templates in production?

i'm developing my first Angular2 app and i'm using this folders structure:
components
component1
home.component.ts
home.component.html
home.component.scss
I'm using Gulp to run tasks for building the app. The final folders structure will be this one:
scripts
somefile1.js
somefile2.js
...
styles
mine.css
vendor.css
index.html
favicon.ico
Can you tell me what is the best way to incorporate HTML templates within Javascript files?
Besides i would be able to easily debug code, so i would see the original folders structure in browser's inspection tools.
I'm currently using gulp-sourcemaps plugin and sourceMap option set to true for Typescript compiler to do the same for Styles and Scripts.
What node plugins could i use to reach this purpose for HTML templates?
I've used gulp-angular-embed-templates on multiple projects with great success.
Here is an example task:
gulp.task('embed-templates', () => {
gulp.src('app/**/**.js')
.pipe(embedTemplates({sourceType:'js', minimize: {quotes: true, empty: true}}))
.pipe(gulp.dest('app/'));
});

Script# Unit tests with DOM access

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.

Intellij: Change JUnit Test Class template

I would like to customize the JUnit Test class template however I cannot find it anywhere in settings. This guy has the same problem. I can't find anything in File Templates or Live Templates. I'm using Intellij 11.
This is now solved in the latest IntelliJ IDEA / Android Studio. Go to:
Settings
-Editor
-File and Code Templates
-Code (tab)
-JUnit4 Test Class
edit the code in the right window.
The link provided by CrazyCoder suggests that this is not directly possible but that I you need to add if statements to the Class File Type template. I will probably split the template in two using a big if-else.