Why did JUnit declare setUp and tearDown in camelcase, even though each of them is a single word?



setUp should have ideally be named as setup

I’ve explored if any duplicate method setup is used in its parent hierarchy, because of which they renamed the method to setUp, but couldn’t find any.

Automatic testing with Windows 10 Eclipse JUnit 5 of code that runs in WSL Ubuntu 16.04?


In order to write integration tests that verify whether running a compiled project.jar file yields the desired results, I thought of doing:

  1. Execute a J-unit test that substitutes certain files with test files
  2. Runs the Main of the project.
  3. AssertTrue on certain output file modifications.

However the main is written to be compiled in eclipse, and opened/ran manually from WSL Ubuntu 18.04. So running main from eclipse in windows will not work (It manipulates environment variables and uses input/output piping for several commands that are run in WSL Ubuntu 18.04 so emulating the behavior of WSL for Java testing becomes significantly more difficult than the entire project itself).

Approach 0.

I run the test but do not run the main from the test. Then I manually compile the project, then I manually open up WSL Ubuntu 18.04, then I manually run the java -jar project.jar file.` And then manually inspect the output files.

Approach 1.

  1. I will look up how I can auto-compile a project while running the project.
  2. After reading https://stackoverflow.com/questions/50108739/how-do-i-sequentially-execute-wsl-commands-from-java and https://www.brianketelsen.com/getting-crazy-with-windows-subsystem-for-linux/ I am researching how I can open the WSL Ubuntu 18.04 terminal from java.
  3. I need to find a solution to grasp/maintain control over that launched instance of the WSL Ubuntu 18.04 terminal, so that the test method can execute commands and read the output files from within that instance, since windows is not able to access those output files.


What would be a better/the preferred strategy to test this project?

Тест метода в JUnit

в этом методе происходит реверс слова с использованием рекурсии и без неё.

Вопрос: как можно протестировать метод inverseString ?

 private Jinjava templateRender = new Jinjava();    @PostMapping("/reverseString") @ResponseBody public String inverseString(@RequestParam("text") String text,                             @RequestParam(value = "tailRecurse", defaultValue = "false") Boolean useTaleRecurse) {     Map<String, Object> map = Maps.newHashMap();     if (useTaleRecurse)         map.put("detail", reverseString("", text, text.length()));     else         map.put("detail", new StringBuffer(text).reverse().toString());     return templateRender.render(getTemplate("index.html"), map); }     private String reverseString(String accumulator,String source, int size) {     if (size == 0)         return accumulator;     return reverseString(accumulator.concat(source.substring(size - 1, size)), source, size - 1); } 

Como iniciar Junit en katalon

Muy buenas a todos, me sale este tipo de error cuando quiero iniciar katalon con junit, no entiendo mucho este software, si alguien me puede ayudar.

Este es el Error: An internal error occurred during: “Launching Prueba”. java.lang.NullPointerException

y este es el codigo:

public class Prueba {             private WebDriver driver;          @Before         public void setup() {              driver = new ChromeDriver();              driver.manage().window().maximize();          }         @Test         public void primerTest() {              String url = "http://demo.guru99.com/popup.php";             driver.get(url);         }      @After     public void End() {         driver.close();     } 


java.lang.AssertionError: Status expected: but was: in Junit test

I want to create JUnit test for Rest api and generate api doc. I want to test this code:

Rest controller

@RestController @RequestMapping("/transactions") public class PaymentTransactionsController {  @Autowired private PaymentTransactionRepository transactionRepository;  @GetMapping("{id}")     public ResponseEntity<?> get(@PathVariable String id) {         return transactionRepository                 .findById(Integer.parseInt(id))                 .map(mapper::toDTO)                 .map(ResponseEntity::ok)                 .orElseGet(() -> notFound().build());     } } 

Repository interface

public interface PaymentTransactionRepository extends CrudRepository<PaymentTransactions, Integer>, JpaSpecificationExecutor<PaymentTransactions> {      Optional<PaymentTransactions> findById(Integer id); } 

I tried to implement this JUnit5 test with mockito:

@ExtendWith({ RestDocumentationExtension.class, SpringExtension.class }) @SpringBootTest(classes = PaymentTransactionsController.class) @WebAppConfiguration public class PaymentTransactionRepositoryIntegrationTest {     .....     private MockMvc mockMvc;      @MockBean     private PaymentTransactionRepository transactionRepository;      @BeforeEach     void setUp(WebApplicationContext webApplicationContext,               RestDocumentationContextProvider restDocumentation) {          PaymentTransactions obj = new PaymentTransactions(1);          Optional<PaymentTransactions> optional = Optional.of(obj);                PaymentTransactionRepository processor = Mockito.mock(PaymentTransactionRepository.class);         Mockito.when(processor.findById(Integer.parseInt("1"))).thenReturn(optional);                 this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)               .apply(documentationConfiguration(restDocumentation))               .alwaysDo(document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))               .build();     }      @Test     public void testNotNull() {         assertNotNull(target);     }      @Test     public void testFindByIdFound() {         Optional<PaymentTransactions> res = target.findById(Integer.parseInt("1")); //        assertTrue(res.isPresent());     }      @Test     public void indexExample() throws Exception {             this.mockMvc.perform(get("/transactions").param("id", "1"))                 .andExpect(status().isOk())                 .andExpect(content().contentType("application/xml;charset=UTF-8"))                 .andDo(document("index-example", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), links(linkWithRel("crud").description("The CRUD resource")), responseFields(subsectionWithPath("_links").description("Links to other resources")),                     responseHeaders(headerWithName("Content-Type").description("The Content-Type of the payload, e.g. `application/hal+json`"))));     } } 

I get error:

java.lang.AssertionError: Status expected:<200> but was:<404> 

What his the proper way to to make GET request to the above code? Probably I need to add response OK when message is send back?

Can multidimensional arrays be passed via @MethodSource (junit 5.1)?

I’m trying to pass two-dimensional arrays to a parameterized test. The one-dimensional array works as expected, but junit complains on the second with “Error resolving parameter at index 0”. Is this not supported or am I using the wrong syntax?

(junit 5.1.0)

// This is ok static Stream<int[]> arrayStream1(){     return Stream.of( new int[] {1}, new int[] {2}); }  @ParameterizedTest @MethodSource("arrayStream1") void test1(int[] par) {     assertTrue(true); }  // This is not static Stream<byte[][]> arrayStream2(){     return Stream.of( new byte[][] {{1,2}}, new byte[][] {{2,3}}); }  @ParameterizedTest @MethodSource("arrayStream2") void test2(int[][] par) {     assertTrue(true); }