We are having an issue , where when we run all tests we see some classes repeated. These classes that are repeated are actually incorrectly labeled classes.
Example: Class A and Class B. Run all tests and code coverage shows that Class A has 90% coverage and Class A has 55% coverage.
We believe this is breaking our ide, anyone know how to resolve this?
I have tried clearing the test cache (Setup > Develop > Apex Test Execution > View Test History > Clear Test Data with no change. As well i tried commenting out code that may have called the other class, still no luck.
Interestingly enough this 'bug' is present across our ide's ...dev console, welkins suite, force.com ide... Trying to pin down the cause.
It is present in all the IDE's is because it's also present in your actual Salesforce instance.
Be more specific.
Apex tests run on a server. If you do not have enough coverage you are not allowed to deploy. You probably need to add some tests to the code you'v added to the org. This could also be indication that something else is broken.
Related
I have two apex classes that I am trying to push to production from a sandbox. When I go to validate the change set, it fails on the code coverage part saying that the code coverage is 50% and needs to be 75%. Both of the classes have well above 75% code coverage as one class is at 100% and the other is at 95% from one of the test classes that I wrote within the sandbox. Is there something that I am missing here?
By default all local tests are run during deployment, all custom code your company written (doesn't run tests from installed managed packages. Because they're likely to fail on your required fields and these fails won't stop your deployment).
If you understand what you're doing and are under time pressure to deploy it - you can use the "run specified tests" option & list the test classes. As long as they all have 75% and all triggers being deployed have at least 1% coverage - it'll work. It'll also be quicker. You can do it in the changeset deployment UI as well as in sfdx deploy command options.
But it's a bit of "pro" move, I wouldn't do it unless you have some CI setup and something runs all tests in a sandbox from time to time. You could deploy without realising you've broken functionality you thought is unrelated. It's bit like deploying a new required field or validation rule - "what could possibly go wrong", it's just config, tests don't need to run... boom, headshot.
Proper way to do it would be to refresh sandbox from prod, deploy your code there, run all tests, keep investigating until you bring whole org back to 75%+ and then deploy that.
I am working on a new project where the client's pre-existing production code has a low coverage of 72% thus not allowing me to deploy any work done in the Sandbox.
Error:
Code Coverage Failure
Your code coverage is 72%. You need at least 75% coverage to complete this deployment.
Does anyone have recommendations as to how to increase code coverage?
Compile all classes in production
Run all your unit tests (local ones, no need to run tests that come with managed packages)
Go to Developer Console, Query Editor, tick at the bottom the Tooling API checkbox
Run this query
SELECT ApexClassorTrigger.Name, NumLinesCovered, NumLinesUncovered
FROM ApexCodeCoverageAggregate
ORDER BY NumLinesUncovered DESC
LIMIT 10
It should give you a good idea which classes/triggers are least covered. Some of these will be quick wins, time spent on creating/improving their tests will give you best results in oveall coverage. I mean it's better to spend 1h fixing class that has 60 out of 100 lines covered than class that has 2 out of 4 covered. Work in sandbox till you're > 75%
(there's a chance your sandbox is outdated and somebody created validation rules, required fields etc straight in production without deploying... that's why I asked to compile & run all tests in prod)
If there are classes/methods that aren't used anymore and it'd be safe to delete them - you can't do it with changeset, you need a special destructive deployment. For now you could comment them out and deploy that version. Just check if this is beneficial for you (I mean of course it's good to get rid of old code, easier maintenance... but if it happens to be well covered with tests you'll shoot yourself in the foot)
Add the created/updated test classes to changeset and you should be able to deploy it to prod.
I'm trying to analyze ongoing ReactJS project using SonarQube (first time with that tool) version 6.7.5 but after second code scan I'm getting Quality Gate failed due to 0% Coverage on New Code and 5% Duplicated Lines on New Code.
First problem - I have no clue why I'm getting it at all (no coverage on new code) when I see new code got picked up by SonarQube. It looks like most of functional components are not covered by tests.
Second problem - duplicates. Most of them are false positive like import statements or declarations (ex. react-table and columns declaration). Is there any way to mark them as non-duplicate? Or is there any workaround to get those kind of code blocks as valid (not dups)?
To touch on your first question:
Do you have the prerequisites set up?
https://docs.sonarqube.org/latest/analysis/languages/javascript/
And have you configured reportPaths and a reporter?
I think that SonarQube needs this to run concurrently with your testing framework's coverage tool to analyse the overall project coverage data.
https://docs.sonarqube.org/latest/analysis/coverage/
Your second issue might be sorted by the first solution.
(I'm actually here because of my own problem: SonarQube isn't analysing a React component / JSX correctly and is seeing it as a code duplication. It's not my project, so I might just have to ask higher up to upgrade SonarQube... hopefully that solves it for me.)
I am using Selenium framework for my test cases execution.
I need an instant report of test cases that are passed while the full suite is in execution currently.
For Eg: There are 100 test cases in suite and five have run of which 3 passed, 2 failed and I need these instant report while the suite is in-progress. Can you please help me with this task?
You can use ExtentReport.
You can use it to log your test steps and once its done it will generate a report to show your results.
For what your looking for, ExtentReport uses a "flush".
If you call this flush after each test step it will amend the step and create the report.
This is something I'm looking into myself at the moment, so I wouldn't consider this an answer but something I've stumbled across myself, hope it helps.
Here is how to set up ExtentReports on your project with examples - http://www.ontestautomation.com/creating-html-reports-for-your-selenium-tests-using-extentreports/
You must use it in conjunction with a test runner eg. TestNG or JUnit.
For what you are trying to achieve is slightly different to the example. You need to call a flush after every test step so it will amend to the report after the step is completed rather than when all the tests are completed. Its not something I have done before but it was explained to me like the following
Just call .flush() after every test instead of once at the end of your test run. BUT you need to make sure the ExtentReports object itself is only initialized once, instead of being reinitialized at the start of every test. For example, I used TestNG. The ExtentReports is called once using #BeforeSuite, but the .flush() is called after every test using #AfterMethod. I hope this makes sense.
The only thing that can’t be solved via code is the HTML refresh as this is outside the control of the ExtentReports library (it doesn’t know where you’ve opened the actual HTML file). But this can be taken care of by using a simple browser plugin as I said. At least for Chrome there are a lot of them, just do a Google search for ‘chrome auto refresh’.
Hope this helps. If you need anymore advice don't hesitate to contact me.
hi i got a reply from u but i checked "author apex" page even though its getting problem and also i have tried in apex IDE here also i am getting this error(i.e test coverage of selected apex trigger is 0 at least 1 % test coverage is required) while moving the apex class from developer edition to enterprice edition so kindly let me know as soon as possible.
You should create a test method class that makes use of the apex trigger. This will take care of the code coverage problem. You then deploy the test class, and your new class at the same time.
Whenever you deploy to production, the system performs a "Run All Tests". So, if there are any failing tests, or if there is any insufficient code coverages, your deployment will fail.