Due to objective reasons, sometimes I only receive the PRD (Product Requirements Document) after the project development is completed. Therefore, in the early stages of development, it is easier to identify issues by establishing clear business processes through certain means rather than diving directly into development. Compared to traditional documentation (DD documents), BDD (Behavior-Driven Development) features may be easier for non-developers to understand.
Documentation tends to lag behind, but it helps me or other colleagues who take over the project in the future to quickly review or understand the requirements of a particular business.
Sample Project Start
Project stratification:
Code:
Take functional configuration single upline operation as an example
classinterface ConfigurationCmdService{ /** * online * * @param cmd * @return */ Result<Boolean> online(ConfigOnlineCmd cmd); } /** * The interface needs to implement the on-line function * Assume that the operation requires only 3 steps: * 1. Find out the configuration that needs to go live * 2. Go live operation * 3. Update the db */ classclass ConfigurationCmdServiceImpl implementsConfigurationCmdService{ privatefinal ConfigRepository repository;
Feature:Configured crud operations Scenario:Online a configuration Given The following configurations exist |id | content| status | bizCode | |1 |xxxxx | AUDIT | XXXX | |2 |xxxxx | DRAFT | XXXX | When id is "1" on line | languageType | bizCode | | zh_CN | 008 | Then The configuration status of id "1" is "On-line"
@Given("The following configurations exist") publicvoid The following configurations exist(DataTable dataTable) { //Create contents based on dataTable List<Config> configs = ConfigTransform.transToConfig(dataTable.entries()); contentRepository.createAll(configs); }
@Then("The configuration status of id {string} is {string}") publicvoidThe_configuration_status_of_id_is(String id,String status){ Configconfig= configRepository.queryById(id); //判断结果 Assert.assertEquals(config.getStatus(),codeMap.get(status)); }
@When("id is {string} on line") publicvoidid_is_on_line(String id){ //Create command ContentCreateParamparam= createOnlineCmd(id); //Get Results result = cmdService.online(param).getData().toString(); }
Step 4
mock db, external services. Take mock db as an example
DB uses a map to mock database operations
The reset operation is used to empty the map, and the map is automatically emptied for each use case.