I'm developing webcomponents with Polymer v2 and unit tests with web-component-tester, which uses Mocha.
The components developed are charts/graphs and need some configuration to be displayed (data especially), so the suiteSetup adds boilerplate for the charts to be displayed correctly.
How could I reuse this boilerplate for other usages than unit tests ?
Is there any standard way ?
For example, I would like to use this codebase as a workbench to work on a chart without integrating it in a real app. The primary issue I have, is that Mocha closes the iFrame containing the components as soon as the tests are done. So I can't even see what it looks like, and can't interact with it.
This codebase could also be reused in a demo gallery of existing charts
Thanks in advance
the simplest approach that is probably used for most of the the behaviors is to have a specific "demo implementation".
e.g.
demo/index.html
demo/my-behavior-demo.html
test/index.html
my-behavior.html
demo/index.html
<link rel="import href="my-behavior-demo.html">
<body>
<my-behavior-demo></my-behavior-demo>
</body>
you could easily reuse the same concept for tests.
Related
I am currently working on a Laravel CRUD application and I was wondering why PHPUnit does not support crawling the browser (anymore, as I read). I already covered the basement of my project via PHPUnit, but I do also want to test links, a tags, button clicks etc. So I do already have a strong basement of unit tests.
Now I read about Dusk providing a crawler for DOM tests. Shall I use both together (is it even possible?) or should I migrate to Dusk? I'm not sure whether Dusk provides the same functionality as PHPUnit does and as stated, I do already have a strong phpunit testing base.
From now on I'm kinda stuck, because of 50:50 testcases, as I do also need to test whether the DOM does provide the correct information.
Appreciate any help or expert advice.
Thank you in advance!
Dusk is not a crawler but a browser driver, it can control a (headless) browser.
Specifically designed on top of PHPunit to do E2E (end to end) testing.
So convert to Dusk what is browser tests (html/javascript), but everything else keep as unit tests.
API tests for example you don't need dusk at all.
Migrating from an MVC-pre-Core project to a Core 2 version I'm shocked to find #Scripts & #Styles are removed. I had relied on being able to use #Scripts.Render("~/bundles/myApp") as a short cut that imported a half dozen files on any page that needed them. Now I have to spell all those files on each page that needs them?
Any way to replicate the behavior. Have glanced at Gulp but seems more like exclusively a processor for deployments.
The Scripts.Render and Styles.Render methods don't actually do anything other than add a simple tag to the generated HTML. The meat of what you're talking about - having a bunch of script/styles rolled up in one call - is the bundling provided by MVC. In ASP.NET Core, the method of creating those bundles has simply changed; that is all.
Now, you have bundleconfig.json, instead of BundleConfig.cs. Instead of calling Scripts.Render to include the bundle, you simply reference the bundled script directly. Likewise with your style.
By default, there is a single bundle for each site.js and site.css that are "bundled" (and minified) into site.min.js and site.min.css, respectively. So, you'd just do:
<environment names="Staging,Production">
<script src="~/js/site.min.js" asp-append-version="true"></script>
</environment>
The environment tags simply determine when this HTML will be included in the output. Here, that's only when the enviroment is Staging or Production. The script tag is a hard-reference to the "bundle". This is functionality equivalent to what you would have achieved with something like:
#Scripts.Render("~/bundles/site")
Which, itself, would only have rendered the following script tag:
<script src="~/bundles/site?v=abc123"></script>
In other words, you don't need the Scripts.Render and Styles.Render methods, since they're pretty useless actually. Even in previous versions of MVC, you could have avoided them and just created tags directly pointing to your bundles.
For more information on how bundling and minification works in ASP.NET Core, see the documentation.
I am going to work on Adobe CMS (CQ05) & Adobe SiteCatalyst based eCommerce website.
Can you advise-
Where can we automate the tests?
[As for any other CMS based solution, pages tend to be very dynamic & UI based automated record-playback execution can fail because of changes in screen]
Please suggest- where do you see opportunity to automate?
What tools one can used?
I will have access to CMS framework but no access to the code, testing code is out of scope.
Many Thanks in advance.
You can script your UI tests with Selenium instead of recording/play mode. Usually you record your scenario to build a test skeleton, then you edit the generated test to rely on elements you are sure to be present during the test (element id, etc.)
I realize this is a duplicate of about 20 different posts, but none of them are specific to MVC4, and none that I've seen really answer all of my questions. So far my first foray into the world of TDD has been frustrating to say the least. Most of what I've tried to do seems incompatible with MVC 4 or next to impossible without using poorly documented third party libraries I don't quite understand yet.
What I want to be able to do, is write a tests that will test my Controller Actions, The Model they're passing and The View the action is sending the model to. I want to test if the view exists, I want to test if the model being passed is the right type for the view, I'd like some way to test if it will process properly. I also want to be able to test my routes. And testing Authentication filters?
I want a way to unit test ASP.Net MVC that will leave very little to chance.
Testing the Model output of an Action seems easy enough, but testing the views has been next to impossible.
So here's my list of questions:
Once I test the action and get the action result, how do I test to see if the view it wants exists?
How do I test my routes?
How can I test to be sure my views are being processed properly?
What is really "best practice" for THOROUGH unit testing of ASP.Net MVC 4?
How do I unit test forms authentication?
How do I unit test Action Filters?
I'd prefer to use the built in Visual Studio test projects, but if I must use NUnit, I must. I just need to make sure it gets done properly.
Thank you in advance for your responses.
EDIT: I also couldn't get NUnit working with my MVC4 app because of some incompatibly with the version of .NET one of the assemblies was compiled in.
Making sure a view exists
http://haacked.com/archive/2007/12/17/testing-routes-in-asp.net-mvc.aspx/
http://blog.davidebbo.com/2011/06/unit-test-your-mvc-views-using-razor.html
see below
How can I unit test my ASP.NET MVC controller that uses FormsAuthentication?
How-to test action filters in ASP.NET MVC?
no. 4: This is a hard question. How does one test anything thoroughly? Personally, I don't really test the views, other than with the 3 major browsers and my two eyes, as it's hard to test a website and all it's components without actually using it. You have JavaScript firing, CSS stylizing, and it looks different across different browsers. So, to me, it seems like testing the view that thoroughly is a minor part of the overall usability of your site. If you're developing a simple table based report of financial data, test that data hard. If your view is a the base for a fancy Ajax site, maybe don't test the HTML so much as the experience. I know it's not an easy, cut-and-dry answer, but the acceptable level of coverage always involves trade offs.
So I know that unit testing is a must. I get the idea that TDD is the way to go when adding new modules. Even if, in practice, I don't actually do it. A bit like commenting code, really.
The real thing is, I'm struggling to get my head around how to unit-test the UI and more generally objects that generate events: user controls, asynchronous database operations, etc.
So much of my code relates to UI events that I can't quite see how to even start the unit testing.
There must be some primers and starter docs out there? Some hints and tips?
I'm generally working in C# (2.0 and 3.5) but I'm not sure that this is strictly relevant to the question.
the thing to remember is that unit testing is about testing the units of code you write. Your unit tests shouldn't test that clicking a button raises an event, but that the code being executed by that click event does as it's supposed to.
What you're really wanting to do is test the underlying code does what it should so that your UI layers can execute that code with confidence.
Read this if you're struggling with UI Testing
Manually test UI stuff where benefit to cost in automating it is minimal. Test everything under the UI skin ruthlessly. Use Humble Dialog, MVC or variants to keep logic and UI distinct and loosely coupled.
You should separate logic and presentation. Using MVP(Model-View-Presenter)/MVC (Model-View-Controller) patterns you can unit test you logic without relying on UI events.
Also you can use White framework to simulate user input.
I would highly recommend you to visit Microsoft's Patterns&Practices developer center, especially take a look at composite application block and Prism - you can get a lot of information on test driven design.
The parts of your application that talk to the outside world (ie UI, database etc.) are always a problem when unit-testing. The way around this is actually not to test those layers but make them as thin as possible. For the UI you can use a humble dialog or a view that doesn't do anything worth testing and then put all the logic in a controller or presenter class. You can then use a mocking framework or write your own mock objects to make fake versions of the views to test the logic in the presenters or controller. On the database side you can do something similar.
Testing events is not impossible. You can for example subscribe an anonymous method to the event that throws an exception if the event is thrown or counts the number of times the event is thrown.