junit

How to run a single method in a JUnit 4 test class? [duplicate]

删除回忆录丶 提交于 2020-01-05 02:25:06
问题 This question already has answers here : Run single test from a JUnit class using command-line (3 answers) Closed 6 years ago . I have looked at all the similar questions, but in my opinion, none of them give a solid answer to this. I have a test class (JUnit 4 but also interested in JUnit 3) and I want to run individual test methods from within those classes programmatically/dynamically (not from the command line). Say, there are 5 test methods but I only want to run 2. How can I achieve

simulate key press in JUnit tests

核能气质少年 提交于 2020-01-05 02:10:21
问题 I am completely stuck in a java test; it's about sending by the test method the character 'a' to the JTextField of a JFrame component. The JFrame class implements the KeyListener interface, and as such overrides KeyPressed, KeyTyped, and KeyReleased. Along with this, I transfer all the keypressed of the JTextField to the JFrame; inside the JFrame constructor I have : JTextField txf_version = new JTextField(); txf_version.addKeyListener(this); I would like to test this behavior and then to

How to write a test case for a method returning object

痴心易碎 提交于 2020-01-04 14:06:35
问题 I have a method for which the return type is object. How do I create a test case for this? How do I mention that the result should be an object? e.g.: public Expression getFilter(String expo) { // do something return object; } 回答1: try Something like this. If the return-type of your function is Object then replace Expression by Object : //if you are using JUnit4 add in the @Test annotation, JUnit3 works without it. //@Test public void testGetFilter(){ try{ Expression myReturnedObject =

Spring Security Unit Test With Csrf causes HttpServletResponse to not be found

只愿长相守 提交于 2020-01-04 06:30:42
问题 I was unable to find this question asked anywhere else. I have my unit test setup as follows: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) //@DatabaseSetup("classpath:decks.xml") @WebIntegrationTest public class DeckControllerTest { @Autowired private WebApplicationContext context; private MockMvc mockMvc; @Before public void setup() { mockMvc = MockMvcBuilders .webAppContextSetup(context) .apply(springSecurity()) .build(); } @Test

Jacoco is reporting 0 coverage of Kotlin classes by unit tests, in an Android project

馋奶兔 提交于 2020-01-04 05:38:08
问题 I'm using Android Gradle Plugin 3.0.0. I'm migrating an Android app from java to kotlin. My app has classes in Java and Kotlin, and tests are in Java. I run ./gradlew clean jacocoTestReport . This runs both unit tests ( src/test ) and instrumentation tests ( src/androidTest ). The report produced by jacoco in app/build/reports/jacoco/jacocoTestReport/html/index.html doesn't show coverage for Kotlin classes which are indeed covered by unit tests. The report does show coverage correctly from

JUnit & Powermock: Native Library already loaded in another classloader

不羁岁月 提交于 2020-01-04 05:14:10
问题 I have some test classes that need to verify that GLFW-functions were called. But when I want to execute all tests in IntelliJ then I get the error: Native Library lwjgl.dll already loaded in another classloader I use Powermock to verify that the static methods have been called: @RunWith(PowerMockRunner.class) @PrepareForTest({GLFW.class}) public class GlfwWindowImplTest { // ... @Test public void update_swapsBufferAndPollsEvents() { GlfwWindowImpl target = new GlfwWindowImpl(1L); mockStatic

ant excluding files

牧云@^-^@ 提交于 2020-01-04 04:17:24
问题 I have to write an ant target for Junit report. It is an existing application. Some of the Test class files are named as TestSample.java or SampleTest.java. But there are some few java files which are not to do anything with junit testcases are written HeaderTest.java which doesnt extending TestCase. How can i filter these calss files? <junit printsummary="on" fork="off" haltonfailure="false" showoutput="true"> <classpath> <path refid="CLASSPATH_JUNIT"/> </classpath> <batchtest fork="off"

Cobertura showing 0% coverage

巧了我就是萌 提交于 2020-01-04 03:52:47
问题 I'm using Cobertura 1.9.3 with NetBeans 6.8, Ant 1.7.1 and JDK 1.6.0_21 running with -WAR, and EJB, JUnit 4 tests. When I change the line pathelement location="${build.classes.dir}" / to pathelement location="${build.test.classes.dir}" / , there is some coverage (albeit in the wrong classes, it shouldn't be in the testclass, just to show that the environment and .jar locations are set correctly) shown in the html reports. However, when I change it back to pathelement location="${build.classes

Cobertura showing 0% coverage

好久不见. 提交于 2020-01-04 03:52:24
问题 I'm using Cobertura 1.9.3 with NetBeans 6.8, Ant 1.7.1 and JDK 1.6.0_21 running with -WAR, and EJB, JUnit 4 tests. When I change the line pathelement location="${build.classes.dir}" / to pathelement location="${build.test.classes.dir}" / , there is some coverage (albeit in the wrong classes, it shouldn't be in the testclass, just to show that the environment and .jar locations are set correctly) shown in the html reports. However, when I change it back to pathelement location="${build.classes

How to make browser window to run in background when running JUnit with Selenium WebDriver from IntelliJ Idea?

拈花ヽ惹草 提交于 2020-01-04 03:28:10
问题 I am running automation tests on Selenium WebDriver as JUnit tests from IntellijIdea. When a browser opens and some actions are being done in it then it always brings itself to the front, even if I have tab-ed to other window. This is not very convenient. Some tests run for few minutes and I would like to be able to work on some other tasks while they are running. Or in case if I want to run the whole suite I can't just sit and watch for 30 minutes. I started to have this problem after I