junit4

Test default value and setter in same test-case or separate test cases

主宰稳场 提交于 2019-11-29 00:56:38
Would you recommend doing any grouping of test cases within @Test methods, or have one @Test method per test scenario? For example, let's suppose that there are different ways to set the context in an application. Is the following idea acceptable? @Test public void testContextSetting() { // Test default setting assert(...) // Test setting a context variable assert(...) ... } Or, would you rather suggest having it like this, having each method as atomic as possible: @Test public void textDefaultSetting() { // Test default setting assert(...) } @Test public void testSettingContextVar() { // Test

Android: Robolectric does not support API level 1

独自空忆成欢 提交于 2019-11-29 00:48:27
问题 This is my basic test class: @RunWith(RobolectricTestRunner.class) public class MainActivityTest { @Before public void setup() { //do whatever is necessary before every test } @Test public void testActivityFound() { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); Assert.assertNotNull(activity); } } When I execute my test under Android Studio, with the Terminal window, I have this error: java.lang.UnsupportedOperationException: Robolectric does not support API

Running “pure” JUnit 4 tests using ant

你说的曾经没有我的故事 提交于 2019-11-28 22:29:36
问题 We have migrated to both JUnit 4 and ant 1.7 The tests runs fine in eclipse, but the annotations are ignored when running the tests using ant. According to the Ant junit task documentation: It also works with JUnit 4.0, including "pure" JUnit 4 tests using only annotations and no JUnit4TestAdapter. But the documentation doesn't elaborate on how it should be configured. Is there any special setting required for the junit task? Am I missing something? We have both Tests that extends TestCase (i

Does TestNG support something like JUnit4's @Rule?

折月煮酒 提交于 2019-11-28 22:28:19
Does TestNG have something like @Rule ? I am thinking specifically about: @Rule public TemporaryFolder folder = ... Or even @Rule public MethodRule globalTimeout = new Timeout(20); I am aware that I can manually implement these things using setUp() and tearDown() equivalents, but these don't give me the convenience that I get using @Rule . Cedric Beust Rules are pretty easy to emulate, for example with super classes: public void Base { @BeforeMethod public void createTempDir() { ... } @AfterMethod public void deleteTempDir() { ... } } public void MyTest extends Base { @Test ... } If you extend

JUNIT Test class in Eclipse - java.lang.ClassNotFoundException

拥有回忆 提交于 2019-11-28 21:00:54
I'm trying to run my junit test (to verify that a properties file loads correctly) but I get ClassNotFoundException although the class is there and all required libraries are there too. Here it is the error I get : Class not found ConfigurationManagerTest java.lang.ClassNotFoundException: ConfigurationManagerTest at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass

When using JUnit's @Parameterized, can I have some tests still run only once [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 20:54:42
问题 This question already has an answer here: Excluding a non param test in parameterized test class 9 answers I use @Parameterized in many cases to run tests on a number of permutations. This works very well and keeps the test-code itself simple and clean. However sometimes I would like to have some of the test-methods still run only once as they do not make use of the parameters, is there a way with JUnit to mark the test-method as "singleton" or "run-once"? Note: This does not concern running

Executing JUnit 4 and JUnit 5 tests in a same build

筅森魡賤 提交于 2019-11-28 20:24:40
In Maven projects, I have some existing tests relying on JUnit 4. I cannot migrate these tests in JUnit 5 for multiple reasons. Essentially, some tests depend on a library which uses JUnit 4 runner and code migration may take time. I would like all the same create new test classes with JUnit 5 that is now released and provides new interesting features. How to do that ? JUnit 5 provides a way out of the box . JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage Each one is a distinct project and using all of them allows to compile and execute JUnit 4 and JUnit 5 tests in a same project.

The differences between JUnit 3 and JUnit 4 [closed]

我的未来我决定 提交于 2019-11-28 20:05:46
Could someone describe in a few words what the main differences between JUnit 3 and 4 are? Paul Sanwald Java 5 annotations for setup and teardown ( @before and @after ) instead of setUp() and tearDown() . don't need to extend TestCase anymore. @Test annotation replaces testSomeMethod() naming convention. static imports for asserts. Junit theories, which allow you to separate data sets from the test itself. 来源: https://stackoverflow.com/questions/6685730/the-differences-between-junit-3-and-junit-4

JUnit tests always rollback the transactions

时光毁灭记忆、已成空白 提交于 2019-11-28 19:16:38
I'm running a simple JUnit test agains an application DAO. The problem is that I always get: javax.persistence.RollbackException: Transaction marked as rollbackOnly The JUnit test is: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:com/my/app/context.xml"} @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false) @Transactional public class PerformanceTest { @Test @Transactional(propagation= Propagation.REQUIRES_NEW) @Rollback(false) public void testMsisdnCreationPerformance() { // Create a JPA entity // Persist JPA

JUnit expected tag not working as expected

丶灬走出姿态 提交于 2019-11-28 18:37:31
I have the following test case in eclipse, using JUnit 4 which is refusing to pass. What could be wrong? @Test(expected = IllegalArgumentException.class) public void testIAE() { throw new IllegalArgumentException(); } This exact testcase came about when trying to test my own code with the expected tag didn't work. I wanted to see if JUnit would pass the most basic test. It didn't. I've also tested with custom exceptions as expected without luck. Screenshot: The problem is that your AnnounceThreadTest extends TestCase. Because it extends TestCase, the JUnit Runner is treating it as a JUnit 3.8