Skip to content

Sociable unit testing as first-class citizen? #230

@soryy708

Description

@soryy708

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

Automock as it is right now is great for solitary unit tests, but I often have a problem. When I refactor production code, I sometimes want to extract a new class to structure things better. However, because Automock assumes that a unit is only a single class, it makes it hard to change the existing unit tests to correctly use the new class. The conceptual unit didn't change, it's only a structural refactor, so it shouldn't be mocked.

It's inconvenient to work-around it right now, with:

const u1 = TestBed.create(Service1).compile();
const dep = u1.unitRef.get(Service3);
const u2 = TestBed.create(Service2).mock(Service1).using(u1.unit).mock(Service3).using(dep).compile();

Describe the solution you'd like

I'd like to be able to conveniently define which classes should not be mocked, because they're part of the unit under test.
Maybe something like:

TestBed.create([Service1, Service2]).compile();

What is the motivation / use case for changing the behavior?

mockists insist upon solitary unit tests, while classicists prefer sociable tests.

https://martinfowler.com/bliki/UnitTest.html

It would be great to support classicist strategies.


[...] tests [...] coupled to things that they should not be coupled to. In the case of his micro-tests, he was using too many mocks, and deeply coupling his tests to the implementation of the production code. That, of course, leads to fragile tests.

https://blog.cleancoder.com/uncle-bob/2017/05/05/TestDefinitions.html

I think coupling the tests to the classes structure too tightly is undesireable because it can lead to fragile tests.

http://xunitpatterns.com/Fragile%20Test.html

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions