Replies: 2 comments 2 replies
-
@sacrejohn I think it depends on what you intend to test, and whether you are doing unit tests or integration tests. I typically write unit tests for
Then I write integration tests for the business layer, typically running against an in-memory "database" using a mock DAL. This test code is basically like the UI code that would be interacting with the domain business types. Sometimes I've written UI tests, though usually (in my experience) this is done by a dedicated QA group that writes automated tests using a variety of tools (such as Playwright). It sounds like you are wanting to create UI level tests that run against mock domain objects? Many years ago, @JasonBock did a bunch of work in this space, and the outcome of that is that all the root base class types (like You can also mock Again, what I personally do, as a general rule, is to create a mock in-memory database. Either by hand or by using the in-memory features of Entity Framework. This way I avoid mocking the domain classes or the data portal, and allow the UI integration tests to execute against a "real" database with a guaranteed known starting data set for each run (because it is in-memory). |
Beta Was this translation helpful? Give feedback.
-
FWIW, even as the author of the aforementioned Rocks framework, I generally avoid using mocks When I've used CSLA in the past (and I mean a decade or farther in the past), it was really hard to any kind of "isolated" unit testing. This was really problematic if large object graphs were in play. Long story short, with changes in CSLA, that became easier to do, but still not ideal. I haven't had to do that in a while though, so maybe things have changed? If you can test your classes isolated, IMO that is the ideal thing to do, but that's not always easy. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I’m working with the CSLA framework and using factories to access my business objects (BO). The factories encapsulate operations like Create or Get. My code can easily support injecting factories as interfaces, which would simplify testing by replacing real implementations with mocks.
However, my BOs (especially editable ones) directly expose methods like Save, which forces me to also mock the DAL (via DataPortal). This makes me feel like mocking both factories and the DAL is redundant.
Here’s a simplified example:
When writing unit tests, I’m wondering:
Thanks in advance for your insights! 😊
Beta Was this translation helpful? Give feedback.
All reactions