Where and what is my unit test? - angularjs

I have been reading tons of articles on unit testing. I am specifically using angular.js right now and came to the conclusion that unit testing = great. I also understand what unit tests are conceptually, but I honestly have no idea what I am doing or looking for. I already started the angular application and before I continue, I feel like I should start testing units of it. I have started tutorials and everything tells me "how" to do it using jasmine (or the other ones). I have a node project set up that is running Karma and a folder that has some *.js files in it to do all the describing/testing. However, it feels like the "tests" I write in a js sit in that file and do nothing.
What am I looking for? How do I actually view the results of the tests? It is all there, but I have no idea where exactly I am supposed to start. Am I supposed to be able to view the test in the browser? Is it supposed to run and save to a log file? Is it actually supposed to be tied to my ACTUAL code, or is it just rewritten logic that is supposed to mimic my code for testing?
This may be a dumb question, but I have spent a long time trying to figure out what exactly to look for. I noticed in some tutorials people have had little windows that tell them if their tests are failing or not (webstorm I believe) while they are writing the tests.
Any guidance would be greatly appreciated!

Related

What's a good way to navigate code base and find source for a webpage

I'm new to frontend development and thinking about what's a good way to find source code in our code base for a webpage. What I usually do is going to the element tab in chrome dev tool, finding a special class name, and searching that in code base to locate the file. I feel there should be better way for this task. I tried to use source tab in dev tool, but it shows tons of files and folders in navigation column. I also tried to use Components tab since we're using react, but component names are minified to single letters. So want to get suggestions from you folks. How do you usually do this? Thanks!
You have the right idea, the problem is that you are looking at the minified (presumably production) version of the website. In general, while developing a website, you run a development server, in which all of the code (mostly) appears as it is written in your IDE/editor. That way you can find component names and inspect the source code through the chrome dev tools.
You should talk to whoever is currently responsible for the code to help you get a development server running on your machine. Then, you find the component names and then do a "find in files" search through your IDE/editor to see what they are, and where they are used in the code base. There may be many results that you have to sift through. That's par for the course in large code bases until you become more familiar with what goes where. And even afterwards.
I will say; even things that appear simple can be fiendishly complex, so it would be useful for you if the owner of the code could give you a rough outline of how things are organised and why to make navigating the code base easier. But, it will always be a bit hard, and depending on how clean the code is, it might be nearly impenetrable. Good luck.
There are many ways to to find source code or debug Code
①You can use Chrome dev tool
②You can use debbuger in VS
③you can debug your code by puttin debugger in java script code
④browser has good functionality to find
code(For reference please check Image.)

Advice and experience for testing a CN1 app

I would like to start automating the testing of my app written in CodenameOne, but I find it difficult to visualize how to use the TestRecorder (section "Unit Testing") for "industrial" testing.
If anyone here is already using it, could you share a few tips about how you use it?
E.g. how do you use the different "Asserts" buttons, how do you structure your tests into suites and how do you chain them together (e.g. so each test case will start in the right context like where in the navigation structure it is supposed to run), do you need to manually edit the tests, ... And is there anything to be aware of before creating lots of tests interactively, e.g. to avoid that your tests are invalidated by some irrelevant change to your UI?
I read in the blog post from May 2017 that the TestRecorder "wasn’t picked up by many developers and as such it stagnated". I tried TestRecorder and immediately came across a seemingly basis error in it (missing test for null) when recording a test case using the Toolbar, which gave the impression it is still the case. So, if anyone here is using another approach that is working well for you, I'd love to hear about that.
See the test classes we use to test Codename One itself here: https://github.com/codenameone/CodenameOne/tree/master/tests/core
You can use the test recorder to generate a skeleton but you can do this manually just like any test. The test API lets you invoke the app or just pieces of it and perform assertions on the behaviors within.

Trying to find a very basic preact.js setup where I can debug the source code

My question is (I think) fairly simple. I am trying to dig into the internals of preact.js and am unsure how to do so. What I mean is, I can get the framework to work fine; I do so via the webpack build from the preact-boilerplate setup. Again, works fine, but there seems to be so much transpiling and source-mapping and hot-loading and whatever the heck else makes these frameworks so quick and fancy that I can't seem to actually intercept the code so I can do boring debugging stuff like console.log and such.
Of course, I can find the preact source code in the node_modules folder; however, this code does not seem to be the one that is actually running/compiling. I suspect this is because everything is being transpiled in real time due to webpack or babel or who knows what. Anyway -- I just want a setup where I can use preact.js but where I can actually access the code. Think of a normal website with a jquery file in a tag. Something like that...and while I know I could theoretically do something like add the preact.js to a script tag on the main index.html page, complications arise due to the babel transpilation and such. And as far as there being some way of doing this via a webpack configuration option, that is beyond my pay grade...but such a configuration option would be fine as well. In a perfect world, I would obviously love to have all the fancy webpack stuff, but since this is all for educational purposes, I'd sacrifice that just for the ability to debug the source code...
This is a strange question in that I am actually struggling to make things simple. I feel like I'm asking to watch TV, but while the place is lousy with 90 inch flat screens, I just need a simple black and white with vacuum tubes. Any help would be appreciated. Thanks very much.
Here is an example repo for using preact without any transpiler:
https://github.com/developit/preact-without-babel
You may want to copy preact from unpkg.com/preact so you can edit it locally.

How to begin writing code for e2e testing in ionic ?

I am new to ionic and decided that i wanted to integrate testing while building my app. But I am a little confused.
Should i write a test after already written functions? or functions that I will write?
Should I test every function ?
I would appreciate if someone just explains the logic flow for me.
Well, you could look into TDD (Test Driven Development) and that should answer your questions.
However, to provide a short answer here as well; you should write a test first, code later (for the why consult the link above). In practice, testing every function may not be viable, but TDD certainly enforces it.
One thing to note, you wrote E2E, but actually what you'll be doing at the start is Unit Testing your functions (E2E comes later).

Test-Driven Development in CakePHP

I'm using CakePHP 2.3 and would like to know how to properly go about building a CakePHP website using test-driven development (TDD). I've read the official documentation on testing, read Mark Story's Testing CakePHP Controllers the hard way, and watched Mark Story's Win at life with Unit testing (PDF of slides) but am still confused. I should note that I've never been very good about writing tests in any language and don't have a lot of experience with it, and that is likely contributing to my confusion.
I'd like to see a step by step walkthrough with code examples on how to build a CakePHP website using TDD. There are articles on TDD, there are articles on testing with CakePHP, but I have yet to find an in-depth article that is about both. I want something that holds my hand through the whole process. I realize this is somewhat of a tall order because, unless my Google-fu is failing me, I'm pretty sure such an article hasn't yet been published, so I'm basically asking you to write an article (or a long Stack Overflow answer), which takes time. Because this is a tall order, I plan to start a bounty on this question worth a lot of points once I'm able to in order to better reward somebody for their efforts, should anybody be willing to do this. I thank you for your time.
TDD is a bit of falacy in that it's essentially just writing tests before you code to ensure that you are writing tests.
All you need to do is create your tests for a thing before you go create it. This requires thought and analysis of your use cases in order to write tests.
So if you want someone to view data, you'll want to write a test for a controller. It'll probably be something like testViewSingleItem(), you'll probably want to assertContains() some data that you want.
Once this is written, it should fail, then you go write your controller method in order to make the test pass.
That's it. Just rinse and repeat for each use case. This is Unit Testing.
Other tests such as Functional tests and Integration tests are just testing different aspects of your application. It's up to you to think and decide which of these tests are usefull to your project.
Most of the time Unit Testing is the way to go as you can test individual parts of the application. Usually parts which will impact on the functionality the most, the "Critical path".
This is an incredibly useful TDD tutorial. http://net.tutsplus.com/sessions/test-driven-php/

Resources