junit

Creating multiple unit tests from a loop in Java

三世轮回 提交于 2019-12-24 08:17:39
问题 I'm writing unit tests for my (small) program, and the test cases are specified in around 30 different files. To test it, all I need is a loop that goes over all the files, parse them, and execute what's needed. The problem is that in that case, all of my tests will be considered as one, since it's all in the same function with the @Test notation. Is it possible to split it somehow without having to have a separate function for each test file? The problem with all the tests as one test case,

Kafka streams tests do not correct work close

谁说胖子不能爱 提交于 2019-12-24 08:14:27
问题 i have 2 unit test when i run them i have the error below 1) test @Test public void simpleInsertAndOutputEventPrint() throws IOException, URISyntaxException { GenericRecord record = getInitialEvent(); testDriver.pipeInput(recordFactory.create(record)); GenericRecord result = testDriver.readOutput(detailsEventTopic, stringDeserializer, genericAvroSerde.deserializer()).value(); Assert.assertEquals(1,result.get("tt")); } 2) Test @Test public void stateStoreSimpleInsertOutputPrint() {

JUnit 5 Collection type parameters cause errors with “@ParameterizedTest”

徘徊边缘 提交于 2019-12-24 07:45:35
问题 I cannot find the reason of the errors from previously asked questions, because they were about "@Test" (which does not allow custom data types). I have a program which takes a String type input (which is usually a block of text), and returns input's sentences in the form of List. To test this program properly I tried to store my inputs and expected outputs (which will be compared to the outputs of my program, purpose of the test) in the form of List. Here DataStructure class consists of 2

Can you get Spring Boot JUnit tests to use the same server?

一世执手 提交于 2019-12-24 07:16:09
问题 I have some Spring Boot JUnit tests that require a somewhat lengthy server start up (I'm loading a complex domain in JPA). I've put them into a test suite, but each test kicks off a new server start up. Is it possible to set them up in such a way that the server is only started once and each test is loaded onto it and run as if the server were started by the test itself? 回答1: Okay, so the solution here is actually built in to Spring testing. That is, it caches ApplicationContexts for tests,

How to test Spring Rest Controller with Mockito.when if controller has HttpServletRequest injected in method

女生的网名这么多〃 提交于 2019-12-24 07:08:03
问题 My Controller looks like this @GetMapping("/networks/{networkId}") public Resource<Network> getNetwork( @PathVariable("networkId") UUID id, HttpServletRequest request) { Resource<Network> network = networkClient.getNetwork(id); network.removeLinks(); network.add(LinkHelper.getNetworkObjectLinkArray(request, id)); return network; } And test looks like so @Test public void getNetwork() throws Exception { Resource<Network> networkResource = createSampleNetwork(organizationId, "Test Network 01");

Exclude ApplicationStartup Event listener when testing

北城余情 提交于 2019-12-24 06:46:19
问题 I recently added an ApplicationStartup class to my SpringBoot project @Component public class ApplicationStartup implements ApplicationListener<ApplicationReadyEvent> { ... It implements ApplicationListener. Now when I run my old JUNit tests that have nothing to do with that class, The testrunner tries to Run my StartupListener, which is neither necessary not appropriate in these cases. How do I skip the ApplicationListener when my tests initialize? @RunWith(SpringRunner.class)

Cucumber Stopping Execution after Time in Steps

青春壹個敷衍的年華 提交于 2019-12-24 04:56:10
问题 One of my tests waits until an event happens in the Then step. If the test works fine there is no issue but if the test is failing (i.e. no event is triggered) then it just hangs. How can I set a timeout in Cucumber ? I know JUnit has a timeout parameter you can use in the @Test annotation, is there something similar for Cucumber ? 回答1: Cucumber has followed the JUnit pattern and offers a timeout parameter in its steps annotations. This takes a long value specifying the number of milliseconds

Allure Framework: using @Step and @Attachment annotations with TestNG and Maven

怎甘沉沦 提交于 2019-12-24 04:31:35
问题 I am working on a project that uses Allure framework with Java, TestNG and Maven. But I'm unable to generate correct XML files while using Allure @Step and @Attachment annotations in my Java program. Any sample code demonstrating usage of the above annotations is appreciated. I am using Allure 1.4.0.RC8. 回答1: These annotations are used in the same way with any Java-based test framework. To create a step: Create method with any visibility modifier (public, private, protected) with step logic

How to log test pass/fail results of JUnit4 to a file?

偶尔善良 提交于 2019-12-24 04:03:12
问题 When a given JUnit4 test runs, I want it to generate a logfile of all of its TestResults. I do not want to invoke this via CI/ant/maven. I want this to run anytime the JUnit test is called from anywhere. If that is not possible, then I would like to write my own runner which problematically invokes my AllTestSuites class and logs all the results itself. Here would be one of my test classes: public class SimpleTestSuite extends TestCase{ @Test public void simpleTestPass() { assertTrue(true); }

EclEmma(Jacocco) shows line not covered even if the line is executed

China☆狼群 提交于 2019-12-24 03:46:09
问题 I am trying improve line coverage for my code. A line gets executed where i am calling a method which in turn will throw an exception. But line coverage shows red color meaning the line was not executed. Code: 1 public void myMethod(SomeService someService){ 2 throwException(someService); 3 } 4 public void throwException(SomeService someService){ 5 THROW an exception here 6 } In my test class I am preparing SomeService required data and calling myMethod from above code. line # 2 shows red