Best EvoMaster code snippet using com.foo.rest.examples.spring.branches.BranchesPostDto
Source:BranchesManualTest.java
1package org.evomaster.e2etests.spring.examples.branches;2import com.foo.rest.examples.spring.branches.BranchesController;3import com.foo.rest.examples.spring.branches.BranchesPostDto;4import io.restassured.http.ContentType;5import org.evomaster.client.java.controller.api.dto.TestResultsDto;6import org.evomaster.e2etests.spring.examples.SpringTestBase;7import org.junit.jupiter.api.BeforeAll;8import org.junit.jupiter.api.BeforeEach;9import org.junit.jupiter.api.Test;10import java.util.Collections;11import java.util.List;12import java.util.stream.Collectors;13import static io.restassured.RestAssured.config;14import static io.restassured.RestAssured.given;15import static org.hamcrest.core.Is.is;16import static org.junit.jupiter.api.Assertions.assertEquals;17import static org.junit.jupiter.api.Assertions.assertTrue;18public class BranchesManualTest extends SpringTestBase {19 @BeforeAll20 public static void initClass() throws Exception {21 BranchesController controller = new BranchesController();22 SpringTestBase.initClass(controller);23 }24 @BeforeEach25 public void reset(){26 //need this, otherwise tests would not be independent27 remoteController.startANewSearch();28 }29 @Test30 public void test(){31 TestResultsDto dto = remoteController.getTestResults(Collections.emptySet(), true);32 assertEquals(0, dto.targets.size());33 given().contentType(ContentType.JSON)34 .accept(ContentType.JSON)35 .body(new BranchesPostDto(5,0))36 .post(baseUrlOfSut + "/api/branches/pos")37 .then()38 .statusCode(200)39 .body("value", is(0));40 dto = remoteController.getTestResults(Collections.emptySet(), true);41 assertTrue(dto.targets.size() > 0);42 List<String> targetDescriptions = dto.targets.stream()43 .map(t -> t.descriptiveId)44 .sorted()45 .collect(Collectors.toList());46 String msg = "TARGETS:\n" + String.join("\n", targetDescriptions);47 assertTrue(targetDescriptions.stream().anyMatch(d -> d.contains("BranchesRest")), msg);48 assertTrue(targetDescriptions.stream().anyMatch(d -> d.contains("BranchesPostDto")), msg);49 assertTrue(targetDescriptions.stream().anyMatch(d -> d.contains("BranchesImp")), msg);50 assertTrue(targetDescriptions.stream().anyMatch(d -> d.startsWith("Line_")), msg);51 assertTrue(targetDescriptions.stream().anyMatch(d -> d.startsWith("Branch_")), msg);52 //FIXME: this pass on its own, but fail when tests run in sequence... need to find why53 //assertTrue(targetDescriptions.stream().anyMatch(d -> d.contains("BranchesResponseDto")), msg);54 /*55 tricky: this does not get instrumented.56 possible theory is that, being used directly from a org.evomaster class,57 it gets loaded before agent kicks in???58 */59 assertTrue(! targetDescriptions.stream().anyMatch(d -> d.contains("BranchesApplication")), msg);60 }61}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!