Test Factory Method Source
Unit tests for the Factory Method Design Pattern implementation.
This file contains GoogleTest cases to validate the behavior of the Factory Method Design Pattern implementation. It tests different concrete creators and their respective products to ensure the correct functionality of the factory method.
Functions
-
TEST(FactoryMethodTest, ConcreteProductA)
Tests the creation and usage of ConcreteProductA through ConcreteCreatorA.
This test case verifies that the
ConcreteCreatorAcreates a product of typeConcreteProductAand that itsuse()method returns the expected string.
-
TEST(FactoryMethodTest, ConcreteProductB)
Tests the creation and usage of ConcreteProductB through ConcreteCreatorB.
This test case verifies that the
ConcreteCreatorBcreates a product of typeConcreteProductBand that itsuse()method returns the expected string.
-
TEST(FactoryMethodTest, FactoryWithBaseCreator)
Tests the Factory Method using base class references.
This test case demonstrates polymorphic behavior by using base class references for both creators and products. It ensures that
ConcreteCreatorAandConcreteCreatorBcorrectly create their respective products, and that the products behave as expected.