junit4

How to get selected option using Selenium WebDriver with Java

南楼画角 提交于 2019-11-28 18:15:11
I want to get the selected label or value of a drop down using Selenium WebDriver and then print it on the console . I am able to select any value from the drop down, but I am not able to retrieve the selected value and print it: Select select = new Select(driver.findElement(By.id("MyDropDown"))).selectByVisibleText(data[11].substring(1 , data[11].length()-1)); WebElement option = select.getFirstSelectedOption(); But all my efforts were in vain. How do I get the selected option? Justin Ko You should be able to get the text using getText() (for the option element you got using

What is the correct way to write to temp file during unit tests with Maven?

▼魔方 西西 提交于 2019-11-28 17:44:20
I have written a unit test that writes a file to the file-system, given no path it writes to the working directory; so if executed from the project directory it writes in the project root, if in the projects parent directory it writes to the parents root directory. So what is the correct way to write to the target directory? Quite possibly a directory inside the target directory? If I quite simply specify target/ with the file it will write to the parent projects target instead of the projects target. UPDATE : I actually want the file after the test finishes. The file is for an extraction

Easy way to get a test file into JUnit

拥有回忆 提交于 2019-11-28 17:42:05
Can somebody suggest an easy way to get a reference to a file as a String/InputStream/File/etc type object in a junit test class? Obviously I could paste the file (xml in this case) in as a giant String or read it in as a file but is there a shortcut specific to Junit like this? public class MyTestClass{ @Resource(path="something.xml") File myTestFile; @Test public void toSomeTest(){ ... } } You can try @Rule annotation. Here is the example from the docs: public static class UsesExternalResource { Server myServer = new Server(); @Rule public ExternalResource resource = new ExternalResource() {

Maven3.0+Spring MVC4+Spring 4+Mybatis3+junit4

ぃ、小莉子 提交于 2019-11-28 17:40:02
一、安装java环境(略) 这方面资料很多 我的环境是JDK6+eclipse4 j2ee版,自带Maven等一些插件 二、安装Maven(略) Maven安装简单装好后修改 根目录/conf/settings.xml,配置好maven库目录 打开eclipse windows-preference-maven-userSettings-global settings选择maven安装目录的settings.xml文件 点击maven在主配置上勾选,这时maven会下载index可能会很慢。需要等等 三、创建maven工程 点击Eclipse菜单栏File->New->Ohter->Maven->选择项目目录->next->选择项目类型 搜索web,创建项目->next 填写groupId和artifact Id->finish 项目配置 右击项目-new 创建如下几个文件 配置build path 分别修改输出路径为 src/main/resources  对应  target/classes src/main/java  对应  target/classes src/test/resources  对应  target/test-classes src/test/java  对应  target/test-classes 设置JDK版本 设置部署程序集(Web

Why is JUnit 4 on Android not working?

会有一股神秘感。 提交于 2019-11-28 16:43:39
问题 as the documentation of Android says, "Note that the Android testing API supports JUnit 3 code style, but not JUnit 4." (Testing Fundamentals). It should be clear that JUnit 4 cannot be used out of the box with Android. But why is this the case? Is it because the tests are executed within the DVM (in that the Android Runtime only has support for JUnit 3)? On a JVM one on its own could choose the JUnit runtime that should be used. Isn't this possible within the DVM? 回答1: Update 2015/10 It is

Writing a single unit test for multiple implementations of an interface

与世无争的帅哥 提交于 2019-11-28 16:37:45
问题 I have an interface List whose implementations include Singly Linked List, Doubly, Circular etc. The unit tests I wrote for Singly should do good for most of Doubly as well as Circular and any other new implementation of the interface. So instead of repeating the unit tests for every implementation, does JUnit offer something inbuilt which would let me have one JUnit test and run it against different implementations? Using JUnit parameterized tests I can supply different implementations like

How do I assert my exception message with JUnit Test annotation?

主宰稳场 提交于 2019-11-28 14:59:06
I have written a few JUnit tests with @Test annotation. If my test method throws a checked exception and if I want to assert the message along with the exception, is there a way to do so with JUnit @Test annotation? AFAIK, JUnit 4.7 doesn't provide this feature but does any future versions provide it? I know in .NET you can assert the message and the exception class. Looking for similar feature in the Java world. This is what I want: @Test (expected = RuntimeException.class, message = "Employee ID is null") public void shouldThrowRuntimeExceptionWhenEmployeeIDisNull() {} Jesse Merriman You

Why should I use Hamcrest-Matcher and assertThat() instead of traditional assertXXX()-Methods

若如初见. 提交于 2019-11-28 13:38:38
问题 When I look at the examples in the Assert class JavaDoc assertThat("Help! Integers don't work", 0, is(1)); // fails: // failure message: // Help! Integers don't work // expected: is <1> // got value: <0> assertThat("Zero is one", 0, is(not(1))) // passes I dont see a big advantage over, let's say, assertEquals( 0, 1 ) . It's nice maybe for the messages if the constructs get more complicated but do you see more advantages? Readability? 回答1: There's no big advantage for those cases where an

JUnit Local Test - 'Unresolved reference: test'

左心房为你撑大大i 提交于 2019-11-28 11:02:02
问题 Expected Importing libraries such as androidx.test:core:1.2.0 , androidx.test.ext:truth:1.2.0 , com.google.truth:truth:0.44 , and etc. into a local JUnit test class named ExampleUnitTest.kt . Observed Error Unresolved reference: test Implementation ExampleUnitTest.kt import androidx.test.core.app.ApplicationProvider.getApplicationContext import com.google.common.truth.Truth.assertThat 回答1: Solution This appears to be an issue documented in the Android Testing Codelab sample app. Within the

Does Junit reinitialize the class with each test method invocation?

我的梦境 提交于 2019-11-28 10:52:22
When i run the below code, both test cases come true: import static junit.framework.Assert.assertEquals; import org.junit.Test; public class MyTest{ private int count; @Before public void before(){ count=1; } @Test public void test1(){ count++; assertEquals(2, count); } @Test public void test2(){ count++; assertEquals(2, count); } } EXPECTED BEHAVIOUR test1 - success test2 - fail(as expected that count will become 3) ACTUAL BEHAVIOUR test1 - success test2 - success Why junit is reinitializing class/variable with each test method invocation. It is a bug in junit or is provided intentionally.