junit

JUnit 5和Selenium基础(二)

浪子不回头ぞ 提交于 2020-01-14 11:32:05
使用Selenium内置的 PageFactory 实现页面对象模式 在这一部分中,将通过Selenium的内置 PageFactory 支持类来介绍 Page Object 模式的实现。 PageFactory 提供一种机制来初始化任何声明 WebElement 或 List<WebElement> 带有 @FindBy 注释的字段的 Page Object 。 由于不可描述的原因,我已经将测试网页打包,需要的请留意文末信息。 介绍页面对象模式 页面对象模式的目标是从实际测试中抽象出应用程序页面和功能。页面对象模式提高了代码在测试和固定装置之间的可重用性,但也使代码易于维护。 页面API或页面对象 我们将从将TodoMVC页面建模为Page Object 的项目开始。该对象将表示将在测试中使用的页面API。可以使用接口对API本身进行建模。如果查看以下界面的方法,则会注意到这些方法只是页面上可用的用户功能。用户可以创建待办事项,用户可以重命名待办事项,也可以删除待办事项: public interface TodoMvc { void navigateTo(); void createTodo(String todoName); void createTodos(String... todoNames); int getTodosLeft(); boolean

JUnit: how to access Spring configuration as Spring has intended?

◇◆丶佛笑我妖孽 提交于 2020-01-14 10:42:51
问题 There is a tutorial video that introduces Spring MVC 3.0. In the demo-project they use the following directory structure: <proj> src main webapp WEB-INF spring appServlet controllers.xml servlet-context.xml root-context.xml Let's say I have a project with Maven-support and I want to write JUnit tests using Spring's configuration. Currently we use JUnit 4.8.2. This would obviously require to load the three files listed above. In the test I could use annotations like @RunWith

JUnit: how to access Spring configuration as Spring has intended?

时光总嘲笑我的痴心妄想 提交于 2020-01-14 10:42:20
问题 There is a tutorial video that introduces Spring MVC 3.0. In the demo-project they use the following directory structure: <proj> src main webapp WEB-INF spring appServlet controllers.xml servlet-context.xml root-context.xml Let's say I have a project with Maven-support and I want to write JUnit tests using Spring's configuration. Currently we use JUnit 4.8.2. This would obviously require to load the three files listed above. In the test I could use annotations like @RunWith

Cleanest way to get a File in a JUnit test case from Maven

烂漫一生 提交于 2020-01-14 10:39:47
问题 My test code in Maven project B (which is a child of project A) has something like String filePath = "src/main/webapp"; //do something with the filePath The above test case runs fine when I run the project from child (i.e, level B) but when I run from Parent project A (i.e, doing a mvn install at parent level) this fails because obviously there is no folder called "src/main/webapp" under parent level (It is however available in child level). I know I could do some coding do check if a test

Unit testing of encrypt/decrypt

蹲街弑〆低调 提交于 2020-01-14 10:32:29
问题 I have implemented a very simple class called Enigma which has a symmetric key and two methods: byte[] encryptString(String strToEncrypt) and String decryptBytes(byte[] arrayToDecrypt) . I am trying to write some tests for the methods. I have thought of testing that the encrypt and decrypt methods are the inverse of each other, but that says nothing about each of them individually. I wanted to use the methods as they are now to obtain a battery of input-outputs and set that as the tests (I

Unit testing of encrypt/decrypt

天涯浪子 提交于 2020-01-14 10:32:10
问题 I have implemented a very simple class called Enigma which has a symmetric key and two methods: byte[] encryptString(String strToEncrypt) and String decryptBytes(byte[] arrayToDecrypt) . I am trying to write some tests for the methods. I have thought of testing that the encrypt and decrypt methods are the inverse of each other, but that says nothing about each of them individually. I wanted to use the methods as they are now to obtain a battery of input-outputs and set that as the tests (I

Junit 4 test suite and individual test classes

只谈情不闲聊 提交于 2020-01-14 08:55:12
问题 I have a JUnit 4 test suite with BeforeClass and AfterClass methods that make a setup/teardown for the following test classes. What I need is to run the test classes also by them selves, but for that I need a setup/teardown scenario (BeforeClass and AfterClass or something like that) for each test class. The thing is that when I run the suite I do not want to execute the setup/teardown before and after each test class, I only want to execute the setup/teardown from the test suite (once). Is

Testing abstract class throws InstantiationException

China☆狼群 提交于 2020-01-14 08:48:30
问题 It's the first time I've written JUnit tests and I came across the following problem. I have to write the tests for an abstract class and I was told to do it this way: http://marcovaltas.com/2011/09/23/abstract-class-testing-using-junit.html However, when I try to run the first test I get an InstantiationException like this: java.lang.InstantiationException at java.lang.reflect.Constructor.newInstance(Constructor.java:526) Here's the test I'm running: /** * Test of setNumber method, of class

How to suppress and verify private static method calls?

强颜欢笑 提交于 2020-01-14 08:43:28
问题 I am currently stumbling in JUnit testing and need some help. So I got this class with static methods which will refactor some objects. For simplification's sake I have made a small example. This is my Factory class: class Factory { public static String factorObject() throws Exception { String s = "Hello Mary Lou"; checkString(s); return s; } private static void checkString(String s) throws Exception { throw new Exception(); } } And this is my Test class: @RunWith(PowerMockRunner.class)

How to suppress and verify private static method calls?

浪尽此生 提交于 2020-01-14 08:43:06
问题 I am currently stumbling in JUnit testing and need some help. So I got this class with static methods which will refactor some objects. For simplification's sake I have made a small example. This is my Factory class: class Factory { public static String factorObject() throws Exception { String s = "Hello Mary Lou"; checkString(s); return s; } private static void checkString(String s) throws Exception { throw new Exception(); } } And this is my Test class: @RunWith(PowerMockRunner.class)