Who has a solution for that common need.  I have a class in my application.  some methods are public, as they are part of the api, and some are private, as they for internal use of making the internal flow more readable  now, say I want to write a unit test, or more like an integration test, which will be located in a different package, which will be allowed to call this method, BUT, I want that normal calling to this method will not be allowed if you try to call it from classes of the application itself  so, I was thinking about something like that  public class MyClass {     public void somePublicMethod() {     ....    }     @PublicForTests    private void somePrivateMethod() {     ....    } }   The annotation above will mark the private method as "public for tests" which means, that compilation and runtime will be allowed for any class which is under the test... package , while compilation and\or runtime will fail for any class which is not under the test package.  any thoughts? is there an annotation like this? is there a better way to do this?  it seems that the more unit tests you write, to more your inforced to break your encapsulation...
3346
How do I unit test (using xUnit) a class that has internal private methods, fields or nested classes? Or a function that is made private by having  (static in C/C++) or is in a private () namespace?  It seems bad to change the access modifier for a method or function just to be able to run a test.
58701
I just want to clarify one thing. This is not a question on which one is better, that part I leave to someone else to discuss. I don't care about it. I've been asked this question on my job interview and I thought it might be useful to learn a bit more.  These are the ones I could come up with:   Java is "platform independent". Well nowadays you could say there is the  project so C# could be considered too but I believe it is a bit exaggerating. Why? Well, when a new release of Java is done it is simultaneously available on all platforms it supports, on the other hand how many features of C# 3.0 are still missing in the Mono implementation? Or is it really  vs.  that we should compare here? Java doesn't support events and delegates. As far as I know. In Java all methods are virtual Development tools: I believe there isn't such a tool yet as Visual Studio. Especially if you've worked with team editions you'll know what I mean.   Please add others you think are relevant.  Update: Just popped up my mind, Java doesn't have something like custom attributes on classes, methods etc. Or does it?
76773
We have a managed package that has executes a HTTP callout from a trigger that calls a future method on the insertion of new records on a particular object.  We have a managed package extension that inserts records on the managed package object which invokes a callout through the managed package.  The problem is in test classes in the managed package extension.  The test classes are failing because it is inserting these records which cause a callout through the managed package.  Normally you would just implement Test.setMock(HttpCalloutMock.class,..) inside the Test.startTest() logic however it is not working.  From what I have read you must implement the Test.setMock method from within the managed package that is actually doing the callout.  Has anyone dealt with this before?  Is the solution as simple as building in logic in the managed package trigger to recognize that it is being executed from a managed package extension and to then invoke Test.setMock from the trigger prior to the attempted callout?  For example:  Option 1:   Managed Package Extension inserts new records  Managed Package Extension sets a global variable value inside of the Managed Package Managed Package trigger fires and looks at the global variable and implements Test.setMock since it was invoked from the managed package extension.   Option 2: Add logic in the trigger to always invoke Test.setMock when it is running in a test context (Test.isRunningTest()).  Thoughts?
48023
Considering "private" is the default access modifier for class Members, why is the keyword even needed?
31511
I have read  about how to test private methods. I usually do not test them, because I always thought it's faster to test only public methods that will be called from outside the object. Do you test private methods? Should I always test them?
98348
in a c++ class declaration, you can label a group of members as private or public, e.g.  private:   int x;   double y;   seems like there's no way to do this in c#. am I wrong?
97115
Is it appropriate to access a class' private members by casting it to a void pointer and then to a struct?    I don't think I have permissions to modify the class that contains the data members that I need to access.  I don't want to take a risk accessing the data members in an indirect way if it is not ethical.  EDIT: Had to edit this further... I am pretty sure the class wouldn't be modified, so it's ok to that extent... my only concern is, if the person who coded that class gets to know of this, it might not go down well with him :(.
47651
I have three questions that I'd like to be clarified.   Is their anyway we could create Custom Metadata in Test Classes? I tried to create on my Test Class but I got an error saying the fields of the metadata could not be writable.  If not, then does that mean we should declare real values in our Custom Metadata and use that instead in our test classes? If (2) is correct, then does this mean we have to create the Custom Metadata in the environment we'll be deploying our code before doing the actual deployment?
101107
I worked on an embedded system this summer written in straight C.  It was an existing project that the company I work for had taken over.  I have become quite accustomed to writing unit tests in Java using JUnit but was at a loss as to the best way to write unit tests for existing code (which needed refactoring) as well as new code added to the system.  Are there any projects out there that make unit testing plain C code as easy as unit testing Java code with JUnit?  Any insight that would apply specifically to embedded development (cross-compiling to arm-linux platform) would be greatly appreciated.
114660
Is it better to have all the private members, then all the protected ones, then all the public ones?  Or the reverse?  Or should there be multiple private, protected and public labels so that the operations can be kept separate from the constructors and so on?  What issues should I take into account when making this decision?
47466
I cannot install Eclipse, even if I wanted to.  It is not approved software for my org.  How can test classes be deleted from production, using deployments? There no 'active' checkbox when I am editing the classes in sandbox mode, so I can't just deactivate the test class, and i cant deploy a deleted class to prod...  how the heck is this done?  I dont want to use ANT or special software.  SF must have a native way to achieve this.  And if not...  then I am very disappointed in humanity.
23015
Should methods in a Java interface be declared with or without the public access modifier?  Technically it doesn't matter, of course. A class method that implements an interface is always public. But what is a better convention?  Java itself is not consistent in this. See for instance Collection vs. Comparable, or Future vs. ScriptEngine.
21668
We are making heavy use of stub and mock objects in our Apex tests. Most of the time we are defining the mocks as inner classes of our test classes. We have noticed, that test classes, which do contain such mock classes do show up at the Overall Code Coverage in the developer console. Such a test class does always have a code coverage of 0% and 0/zz lines covered.  I give a short example. Consider the following class of the business logic:  public virtual class Foo {      public virtual String doSomething() {         return anotherFunction('foo');     }      public virtual String anotherFunction(String value) {         return value;     } }   A typical unit test would look like the following:  @isTest private class FooTest {      private class FooMock extends Foo {         private Boolean anotherFunctionCalled;         private String value;          public override String anotherFunction(String value) {             this.anotherFunctionCalled = true;             this.value = value;              return 'test';         }     }      @isTest     static void testDoSomething() {         FooMock f = new FooMock();          String result = f.doSomething();          System.assertEquals('test', result);         System.assertEquals(true, f.anotherFunctionCalled);         System.assertEquals('foo', f.value);     }      @isTest     static void testAnotherFunction() {         Foo f = new Foo();          String result = f.anotherFunction('blah');          System.assertEquals('blah', result);        } }   The Overall Code Coverage shows the following:    Foo: 100% 4/4 Lines covered FooTest: 0% 0/2 Lines covered   If you click on Apex Classes/Estimate your organization's code coverage you will get the surprising result of 66.67% (4/(2+4)) code coverage, which will not allow you to upload this code as a package.  How can we make sure, that the test classes will not be considered at the coverage estimation?
65346
All my college years I have been using public, and would like to know the difference between public, private, and protected?  Also what does static do as opposed to having nothing?
8179
Suppose I have BaseClass with public methods A and B, and I create DerivedClass through inheritance.  e.g.  public DerivedClass : BaseClass {}   Now I want to develop a method C in DerivedClass that uses A and B.  Is there a way I can override methods A and B to be private in DerivedClass so that only method C is exposed to someone who wants to use my DerivedClass?
47351
Here is a little test program:   #include &lt;iostream&gt;  class Test { public:     static void DoCrash(){ std::cout&lt;&lt; "TEST IT!"&lt;&lt; std::endl; } };  int main() {     Test k;     k.DoCrash(); // calling a static method like a member method...      std::system("pause");      return 0; }   On VS2008 + SP1 (vc9) it compiles fine: the console just display "TEST IT!".  As far as I know, static member methods shouldn't be called on instanced object.   Am I wrong? Is this code correct from the standard point of view? If it's correct, why is that? I can't find why it would be allowed, or maybe it's to help using "static or not" method in templates?
97180
I just started programming Objective-C and, having a background in Java, wonder how people writing Objective-C programs deal with private methods.  I understand there may be several conventions and habits and think about this question as an aggregator of the best techniques people use dealing with private methods in Objective-C.   Please include an argument for your approach when posting it. Why is it good? Which drawbacks does it have (that you know of) and how you deal with them?    As for my findings so far.  It is possible to use  [e.g. MyClass (Private)] defined in MyClass.m file to group private methods.  This approach has 2 issues:   Xcode (and compiler?) does not check if you define all methods in private category in corresponding @implementation block You have to put @interface declaring your private category in the begin of MyClass.m file, otherwise Xcode complains with a message like "self may not respond to message "privateFoo".   The first issue can be worked around with  [e.g. MyClass ()]. The second one bothers me a lot. I'd like to see private methods implemented (and defined) near the end of the file; I do not know if that's possible.