Focus on the behaviour that you want to test. in what externally testable way does MyClass change after addElement is called? this should be the focus of your test.
Tests generally fall into two categories.
- Testing state changes
- Testing interactions
In this case it looks like you are testing state changes (although that's not 100% clear from your cut down example). When testing state changes you generally want to set things up, perform some action and then verify the state of your object has changed in the expected way. In these tests you generally do not need mocks (although you might need stubs to provide test data)
In this case you would add an element and then call some additional method to verify that the element has been added, like trying to get it, or verifying that the number of stored elements had increased. Without more details of what your object actually does its hard to guide you exactly.
the fact that you have a private array list inside your class is an implementation detail and should not be the focus of your test, otherwise if you decide to change the array list for something else in the future your tests will likely need updating.
When testing interactions you generally want to set things up, perform some action and then verify that the interactions that were expected took place. In these tests you might want to use mocks for the interactions you are testing.
For example you might want to check the interaction of your class with another class (like a logger or a database access class) is happening in the expected way.
addwas called