There are few prerequisites to understand how it is possible to A/B Test using templates. Please get aquatinted with following concepts first:
Posts rendering from backend
The article describes <posts> tag that enables placing multiple posts in given place of the layout using specified logic and specified format.
Pulling more content from backend
The article describes how to achieve "posts infinite scroll" behavior or "load more posts button" functionality.
Using URL parameters inside template files
The article describes how to alter layout using URL parameter. This gives base to achieve two or more versions of the same module in website layout.
The last concept gives a way of replacing certain parts of the website with its alternative version. Using this technique its possible to go very deep with alternating website to the point where whole website could have totally different layout when using certain URL parameter. That really depends on a placement of a URL parameters check in template and what they embrace.
When they embrace whole code inside base.xml then it enables complete change of the layout.
Another part of A/B Testing is a tool to collect data of how selected tests are performing. The best for the task is Google Analytics with UTM codes tracking. UTM codes would be used as the URL parameters that trigger different test cases.