You can’t do it directly within Discourse. An external A/B testing tool could potentially work, but it depends on how the tool works and the specifics of the test. There’s a lot of potential variation.
We tend to avoid doing A/B testing ourselves in favor of making individual changes and seeing how the community reacts.