I have EntertainmentController, and `EntertainmentControllerTestClass. Inside test class, I add test method refer to each method in the controller, all of them are empty methods so they all pass when run test. But when I upload to package application, I got the message:
Upload Failed:
No test methods found in the Apex code included in the package. At least 75% test coverage is required.
Apex Tests have to actually test your business classes. Having empty tests serves no purpose. You must write Unit Tests that validate the code in your EntertainmentController class. The Unit Tests must result in 75% of the code in the EntertainmentController being executed without failures during test execution.
Also, when you add your Apex Classes to your package, you have to add both your EntertainmentController and EntertainmentControllerTestClass.
Testing Apex
Related
I'm working on a wizard-style application using AngularJS, and using ProtractorJS for E2E testing. I've defined PageObjects representing various screens and objects on the page.
In writing e2e tests for the app, I've noticed that several of the tests move through several wizard pages in the same way, and I'd like to define reusable sets of tests that I could invoke as part of larger test suites. I've attempted to do this by creating functions which have a describe(... it (...); it(...)) sequence inside but my issue is passing a reference to the new PageObject out of the function, since the test suites are executed after the function has already returned.
I'm writing Protractor tests to verify the successful creation of reports in our application. A report is created via a series of complex UI interactions within a dialog and saved via an AJAX POST request to a REST API.
I've written tests for the complex UI interactions within the modal, but I'm at a loss for how to test the POST request within the same Protractor tests. Ideally, I'd like to be able to make assertions against the payload of the POST request to verify that the UI is sending the correct data to the API.
It's important to note that I do not want to mock the HTTP call--I need it to go through, since subsequent protractor tests navigate to the report and perform additional checks. My first thought was to somehow hook into the $httpBackend.passThrough() method, but I haven't had any success with that.
Any ideas how to accomplish this?
since subsequent protractor tests navigate to the report and perform additional checks
If you check that the report contains data to that matches which was submitted, you are, albeit indirectly, testing that the POST went through successfully. There is a reasonable argument that this is enough for the E2E test: it tests that the application behaves as he user would want. The user doesn't care how it's achieved: POST, websockets, carrier pigeon ;-)
Keep in mind that the usual aim of such tests is for them to fail if something is broken. If the POST isn't done correctly, then the subsequent tests that verify the displayed report would fail.
The downside is that you would have a bit less information about what has gone wrong than if you managed to test the POST as well. However, unit tests can help. If you have a failing unit test that localises the issue, you write a fix that makes it pass. If you don't have a failing unit test, you can investigate the issue by debugging, add a failing test that highlights the issue, and fix the code so it passes.
I am writing an angular application, whereby my controller calls an API, that returns live data which I then display on my html doc.
I am using Protractor for my end to end tests, and jasmine for unit testing.
I am mocking my API call, to ensure the API is not called.
My question is whether I should be testing the API call with protractor, and check whether my html doc is updated following the GET request, or whether I should test the API call when conducting my unit tests with jasmine.
I have a feeling that the answer is that I should be testing this API call with both my unit and end to end tests, but am hoping someone on SO can provide clarity.
The main goal of unit testing is to test that your code (be it JavaScrip or otherwise) is doing what it should. Each test should be done against data that static or contrived and should never be run against an API. Static data gives you the control you need. If your code needs to branch when X equals 7, you can purposely set that value and verify that your code does indeed branch. When you run against an API you do not have that control. Even if you are the one that controls the API, doing unit testing against it is a bad habit to get into.
End to end testing is completely different. Here we are not testing that the code works on a granular level (we already did that in our unit tests) we are testing that the application works as a whole. When a specific button is clicked in the application, did the expected things happen? Do all of the expected elements appear on the page? You still need to be testing against known data, and doing that is just as crucial as in unit testing, but here you get to see how your app reacts against when running. Did a particular screen take too long to load? Did a button click not give you what you expected? This kind of testing lets you click through your application as a user would (except much faster.)
You should run both kinds of tests on your app. Unit tests should be run during the build process, and end to end tests should be run once the build completes.
I am trying to deploy change set which contains Custom fields, Apex classes and test classes from sandbox to production. While executing all test class in Sandbox, Overall Code coverage is 86%. But while deploying to production through change set, getting error message " Details: Average test coverage across all Apex Classes and Triggers is 27%, at least 75% test coverage is required." Please advice.
We can use coverage to see how much javascript code is covered with our unit testing. With e2e testing we are literally testing view components in HTML code against controller. So the question is, is there same code coverage available for how much of HTML DOM elements are covered or touched in our e2e testing? I agree, there is a big difference in the execution path testing and UI testing. but curious.
Thanks
As I know e2e testing use your files served by your web server, for unit test they are served directly by karma, e2e testing is mostly used to be sure your page work like you expect, end-to-end test use your server side and client side. That's why you typically never expected to have 100% e2e coverage because they are more fragile.
So people focus on unit test (testing all edge-cases), and they add e2e test to be sure the behavior of the page works correctly.
You can use istanbul and build the coverage report with karma.
http://gotwarlost.github.io/istanbul/
Or this article : http://lkrnac.net/blog/2014/04/measuring-code-coverage-by-protractor/ sum up how to use protractor e2e to generate coverage report of your e2e tests. Using using this tool : https://github.com/r3b/grunt-protractor-coverage
Hope it's help.