How to unit test works in salesforce?

后端 未结 3 1237
半阙折子戏
半阙折子戏 2021-01-21 08:25

I\'ve done writing code on salesforce and in order to release the unit tests have to cover at least 75%.

What I am facing is that the classOne

3条回答
  •  抹茶落季
    2021-01-21 08:43

    Comments about Java mock libraries aren't very helpful in Salesforce world ;) At my projects we usually aimed for making our own test data in the test method, calling real functionality, checking the results... and whole test framework on Salesforce side is responsible for transaction rollback (so no test data is saved to DB in the end regardless whether the test failed or passed).

    Anyway...

    Masato, your classes do not compile (methods outside class scope, public String hello() without any String returned)... After I fixed it I simply right-clicked the MyClassA -> Force.com -> run tests and got full code coverage without any problems so your issue must lie somewhere else...

    Here's how it looks: http://dl.dropbox.com/u/709568/stackoverflow/masato_code_coverage.png

    I'm trying to think what might have gone wrong... are you sure all classes compile and were saved on server side? Did you put test methods in same classes as functionality or in separate ones (generally I make separate class name with similar name like MyClassATest). If it's a separate class - on which file did you click "run tests"? Last but not least - if you're facing this issue during deployment from sandbox to production, make sure you selected all classes you need in the deployment wizard?

提交回复
热议问题