Post

Settle an argument: what is an integration test, and is that the same as an end-to-end test? Secondly, is testing a React component a "unit test"?

0 reposts48 likes

I prefer to shift my definition for a unit test (and subsequent levels) from testing a unit of logic to testing a unit of behavior. A single behavior may have compound logic. Your function may have deps. Your input relies on a UI framework, a styling framework, etc. Software is rarely simple.

But please note that the testing level separation is not something you should dwell upon. In a sense that I don't care if it's technically a unit test or a functional test or an integration test. What I care is the boundaries of my test and a working product. Test bits, then test synergies.

Hm. I think drawing a line at your app's logic helps. Typing into an input may involve a bunch of behaviors on your UI framework's side, but those aren't your concern. Putting yourself in your user's shoes also help (does my user know about this? no, then it's not my concern either).

This framework of thinking helps me make sense of the testing levels. Whereas basing them on logic was always confusing to me, and it inevitably leads to spending time in discussion instead of spending that time on testing.

FYI if you reply to the most recent reply, it’ll create a chain/thread. Otherwise it’s a tree. 😅

For an open source library, for example, e2e implies packing and installing your package in a test project, then interfacing with it akin to the package's consumer. Similar intent, different specifics inherent to the kind of software.

An e2e test is focused on the behaviors related to entire usage flows. This one is the trickiest to define because the "ends" of your software differ based on the software itself. E.g. for a web app, e2e is the end user interacting in your software in the end environment (the browser).

FWIW 😛 I see e2e tests differently, considering webapps. IMO e2e means that the entire environment takes part in the test : Fe, be, db, network etc. E2E tests don't have to rely on browsers BTW! (see backend contract tests) Integration on the other hand means that more than 1 piece is used /1

There could be a UI integration test, but there could be a backend integration test also (e.g. server side controller communicating with a real socket via HTTP but nothing more than the connection itself, e.g. no DB queries). All in all both E2E and integration could test entire user flows.

I tend to look at the testing level from the behavior's perspective. A unit test asserts a single behavior. I give function a wrong argument, it throws an error. An integration test assertions a combination of multiple behaviors. I type into an input, then click "Submit", then check the result.

That's quite open to interpretation though Prep function args <> type in the input Click submit <> call the function Check the result <> assert function response Where is the line? IMO, it doesn't matter much. People have different defs. How fast/reliably can you verify behavior of your system

Having a common definition helps for teaching. So clarifying the def you use is helpful. But the different shapes of testing strategies are mostly marketing. Testing pyramid, trophy, crab, honeycomb... Under the hood it's the same advice with different definitions of where you draw the line

I draw that line in that submitting a form likely involves multiple things in my app: input state handling, validation, triggering the actual submit. It's a compound behavior, whereas a function call is a simple behavior if we draw the line at function's I/O.

I'll throw my view into here: - An integration test (as opposed to a unit test) involves something that is not defined in the codebase under test. 3rd party API, DB, etc. - E2E tests the full stack, often including several integrations. - Typically yes, but calling it a component test is easier.

Integration tests are a subset of end to end tests and test an integration of layers in your application. For example your back end API with your dB. End to end tests all the integrations. As for RC, it could be either unit or integration depending on scope of what is actually being tested.

i personally use integration and end-to-end interchangeably in the context of frontend code. testing a react component is a unit test for a UI render function my spicy answer for the second question is that testing a React component is a “waste of time” in my experience

Testing a react component can be many types of test. If the paradigm of the application is a thick client. Then the component can have a lot of responsibility. I would argue that testing a react component can vary from e2e to unit test dependent on the scope the component is responsible for.

Integrations tests are different from e2e as they typically mock services and they test apis. Also they can be done solely on backend services or solely on some FE components E2E usually are requirement / user story focused. E2E both assert front- and backend.

can't answer the 2nd question, but we consider integration test when we cross platform software testing and end-to-end is more a network consideration of the same cross platform software testing.

Unit tests are isolated, either because the component being tested is small or because its dependencies are being mocked. Component tests are iffy and may or may not be unit tests. Testing a button component renders its label text prop is, testing an i18n provider with a button probably isn’t.

Integration tests are across components, such as making sure a frontend component calls a backend API correctly. The backend might use a mocked database so the test always passes on a valid request. Can also test error handling with integration tests, such as a login request with an invalid user ID

The way I think of it is: "end to end" is if you test how the end user would experience it (so an actual browser / device all the way down). A "unit" test is testing a single function (so a React component is indeed a unit test). And an "integration" test is anything in between.

Save yourself pain and call them small, medium and large tests. Pretty much everyone can agree on whether a test is small, medium or large. Pretty much no one agrees on what is a unit, integration, system or e2e test.

Maybe tweak that - choose labels based on the distinctions you need to make - eg if you have some expensive tests that only run nightly, label them accordingly. If you don’t need to distinguish, just call them all “tests”.

I mean it's a little pedantic but to me the only real difference is that an integration test likely has some boundary where things outside the boundary are not tested because of any number of reasons. While an e2e is exactly what the name implies no mocking or boundaries applied.

and yeah i think one could refer to e2e as an integration test its just that e2e makes it more clear that there aren't any mocks or boundaries applied.

To me, unit tests only require one system under test. So a react component test can be a unit test if that’s a basic building block in your software. But if you’re testing something that operates at the framework level, that could even be e2e.

Integration tests are just how two or more parts of my system get tested. When I write a test against a MobX-State-Tree store and then checks its impact on a React component, that’s an integration test to me.

I think end to end tests generally need to be at the level of final consumption. For a user facing app, it’s black box testing for the whole system. But for a dev tool, it might be a script that initializes and verifies itself.

For me, an integration test tests a system as one cohesive module. For example testing a service, along with a real database, mocking any calls to external services. In an e2e test those calls will not be mocked. I guess all tests test a unit as a whole. All that varies is what the unit is.

To me any test that requires dependency injection or mocking internal dependencies is very hard to consider a unit test, no matter how small it is. So to me most tests fall in the integration category, including most React components. An e2e test is the ultimate integration test.

E2E drives a headless browser and mimics User interaction Integration tests functions/systems directly. Including external resources (ex DB). Unit tests functions directly but mocks/patches all external resources.

React sucks at unit/integration testing b/c React itself is a 'God Object' anti-pattern. Ie. you can't test any of its parts individually without bringing in the whole framework. In React only E2E testing is feasibly worth the effort.

Shortly, "is testing a React component a unit test?" is in itself not a valid question. A React component test can be a unit test. It can also be an integration test. The testing level changes based on the behavior you want to test. Single behavior = unit test. Multiple behaviors = integration.

End to end tests should test business process from end to end. Integration tests simply test interactions between different parts and are usually smaller in scope then end to end. Unit tests test a single class or component in isolation.

Honestly I am really on the side of … just using the name of the tool. “I’ll add a jest test for that” “Have you finished that Maestro test?” “We need to make sure that’s covered by enzyme tests.”

Yeah, I'm also team "it doesn't matter" and "I don't care." Is the test providing value? Is it fragile? Does it break when you make a normal change? I think the testing pyramid is an outdated idea. When it's up to me, I test using whatever the thing's API is and nothing else.

IMO: Unit tests test an indivisible piece of the software under test. An integration test is any test that isn’t a unit test. e2e tests are the subset of integration tests that deal with user input to user-observable output/effect. All relative to where the boundaries of your software are.

This is why they should just be called small, medium and large tests. A large test for React isn’t the same as a large test for your app. Who cares if it’s a “unit” or not.

For me, unit tests are the ones best written as you specify the component in question and you have it from the get-go, they are tightly bound to their components. Some testing protocols for a whole product or set of components can be written early, but they aren't so tightly bound.

For me: Unit test -> test a part of an app that doesn't rely on external services Integration -> test a part of an app that relies on external services that are mocked End to end -> test a part of an app that relies on external services that are not mocked

To me a unit is just testing a building block, often in isolation w/ a vague “does this generally work”. Integration & e2e tests aren’t super clear to me beyond the size of their coverage in terms of application code and/or feature function.