junit

Run JUnit tests with SBT

若如初见. 提交于 2019-12-17 09:51:14
问题 I have a 0.13.7 SBT project, with several sub-projects. One of them is called webapp , and it has many JUnit tests in webapp/src/test/java . When running: sbt webapp/test only the ScalaTest tests are run, but no JUnit tests. Snippet of my build.sbt file: libraryDependencies ++= Seq( "com.novocode" % "junit-interface" % "0.11" % Test ) lazy val webapp = project settings( Seq( projectDependencies ++= Seq( .... "org.scalatest" %% "scalatest" % "2.2.2" % Test, "junit" % "junit" % "4.11" % Test,

How to run all JUnit tests in a category/suite with Ant?

[亡魂溺海] 提交于 2019-12-17 09:33:03
问题 I'm using JUnit Categories and ClassPathSuite in a setup similar to that described in this answer. To recap: public interface FastTests { } @RunWith(Categories.class) @Categories.IncludeCategory(FastTests.class) @Suite.SuiteClasses(AllTests.class) public class FastTestSuite { } @RunWith(ClasspathSuite.class) public class AllTests { } ...where AllTests makes use of the ClasspathSuite library. A test class that's part of the FastTests category would look like this: @Category(FastTests.class)

How to run all JUnit tests in a category/suite with Ant?

﹥>﹥吖頭↗ 提交于 2019-12-17 09:32:35
问题 I'm using JUnit Categories and ClassPathSuite in a setup similar to that described in this answer. To recap: public interface FastTests { } @RunWith(Categories.class) @Categories.IncludeCategory(FastTests.class) @Suite.SuiteClasses(AllTests.class) public class FastTestSuite { } @RunWith(ClasspathSuite.class) public class AllTests { } ...where AllTests makes use of the ClasspathSuite library. A test class that's part of the FastTests category would look like this: @Category(FastTests.class)

Android RxJava 2 JUnit test - getMainLooper in android.os.Looper not mocked RuntimeException

岁酱吖の 提交于 2019-12-17 08:30:31
问题 I am encountering a RuntimeException when attempting to run JUnit tests for a presenter that is using observeOn(AndroidSchedulers.mainThread()) . Since they are pure JUnit tests and not Android instrumentation tests, they don't have access to Android dependencies, causing me to encounter the following error when executing the tests: java.lang.ExceptionInInitializerError at io.reactivex.android.schedulers.AndroidSchedulers$1.call(AndroidSchedulers.java:35) at io.reactivex.android.schedulers

Eclipse/Maven: JUnit tests not compiled when running them

不问归期 提交于 2019-12-17 08:12:44
问题 I am working on a project using Maven and Eclipse (m2eclipse plugin). I've got problems with the JUnit tests: Sometimes, when running them within Eclipse, they wont be compiled, but the old class files are used instead. When I delete the class files, I get ClassNotFoundExceptions in Eclipse. I then have to manually recompile them by using mvn test-compile or other goals. I also noticed that the class files of the tests sometimes are put into the classes subdirectory instead of test-classes .

Find an element by text and get xpath - selenium webdriver junit

寵の児 提交于 2019-12-17 07:26:51
问题 I have a table with 9 rows and 6 columns in my webpage. I want to search for a text "MakeGoodDisabled-Programwise_09_44_38_461(n)" and get the xpath of the cell. I have used the following but it fails because it is not able to find the text on the page. Can you please help? I am using Selenium Webdriver Junit to code this. List < WebElement > links = driver.findElements(By.tagName("td")); Iterator < WebElement > itr = links.iterator(); while (itr.hasNext()) { String test = itr.next().getText(

How to test code dependent on environment variables using JUnit?

自作多情 提交于 2019-12-17 07:15:24
问题 I have a piece of Java code which uses an environment variable and the behaviour of the code depends on the value of this variable. I would like to test this code with different values of the environment variable. How can I do this in JUnit? I've seen some ways to set environment variables in Java in general, but I'm more interested in unit testing aspect of it, especially considering that tests shouldn't interfere with each other. 回答1: The library System Rules provides a JUnit Rule for

How to test code dependent on environment variables using JUnit?

对着背影说爱祢 提交于 2019-12-17 07:15:05
问题 I have a piece of Java code which uses an environment variable and the behaviour of the code depends on the value of this variable. I would like to test this code with different values of the environment variable. How can I do this in JUnit? I've seen some ways to set environment variables in Java in general, but I'm more interested in unit testing aspect of it, especially considering that tests shouldn't interfere with each other. 回答1: The library System Rules provides a JUnit Rule for

request scoped beans in spring testing

跟風遠走 提交于 2019-12-17 07:14:21
问题 I would like to make use of request scoped beans in my app. I use JUnit4 for testing. If I try to create one in a test like this: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:spring/TestScopedBeans-context.xml" }) public class TestScopedBeans { protected final static Logger logger = Logger .getLogger(TestScopedBeans.class); @Resource private Object tObj; @Test public void testBean() { logger.debug(tObj); } @Test public void testBean2() { logger.debug

Where do I configure log4j in a JUnit test class?

本小妞迷上赌 提交于 2019-12-17 07:13:48
问题 Looking at the last JUnit test case I wrote, I called log4j's BasicConfigurator.configure() method inside the class constructor. That worked fine for running just that single class from Eclipse's "run as JUnit test case" command. But I realize it's incorrect: I'm pretty sure our main test suite runs all of these classes from one process, and therefore log4j configuration should be happening higher up somewhere. But I still need to run a test case by itself some times, in which case I want