How do I customize how I display JUnit test results?
up vote
0
down vote
favorite
When i ues JUnit to test some java function, It will output some results regardless of success or failure.But sometimes it Looks like a bunch of small ants, makes me dizzy.
Perhaps the original intention of generating this output is to make better debugging.
But if there are hundreds or thousands of test cases, the output may not be fully displayed in the console.
So, is there a way to trigger an action when the test fails, just write the failed content to a file or send it to a mailbox?
E.g:
Sntest.java
package com.jut;
public class Sntest
public String getString()
return "String";
public Object getNull()
return null;
SntestTest.java
package com.jut;
import org.junit.Assert;
import org.junit.Test;
import com.jut.Sntest;
public class SntestTest
@Test
public void t1()
Sntest sn = new Sntest();
String msg = sn.getString();
Assert.assertEquals("AString != String", "AString", msg);
@Test
public void t2()
Sntest sn = new Sntest();
Assert.assertNull("Not null", sn.getNull());
In the above example, test method t1 will get the wrong result and display a lot of information, as follows:
Running com.jut.SntestTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.156 sec <<< FAILURE!
t1(com.jut.SntestTest) Time elapsed: 0.025 sec <<< FAILURE!
org.junit.ComparisonFailure: AString != String expected:<[A]String> but was:<String>
at org.junit.Assert.assertEquals(Assert.java:125)
at com.jut.SntestTest.t1(SntestTest.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
But what I want to see is only the first line to the fourth line.So how can I turn the output into the following result?
Running com.jut.SntestTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.156 sec <<< FAILURE!
t1(com.jut.SntestTest) Time elapsed: 0.025 sec <<< FAILURE!
org.junit.ComparisonFailure: AString != String expected:<[A]String> but was:<String>
java maven junit junit4
add a comment |
up vote
0
down vote
favorite
When i ues JUnit to test some java function, It will output some results regardless of success or failure.But sometimes it Looks like a bunch of small ants, makes me dizzy.
Perhaps the original intention of generating this output is to make better debugging.
But if there are hundreds or thousands of test cases, the output may not be fully displayed in the console.
So, is there a way to trigger an action when the test fails, just write the failed content to a file or send it to a mailbox?
E.g:
Sntest.java
package com.jut;
public class Sntest
public String getString()
return "String";
public Object getNull()
return null;
SntestTest.java
package com.jut;
import org.junit.Assert;
import org.junit.Test;
import com.jut.Sntest;
public class SntestTest
@Test
public void t1()
Sntest sn = new Sntest();
String msg = sn.getString();
Assert.assertEquals("AString != String", "AString", msg);
@Test
public void t2()
Sntest sn = new Sntest();
Assert.assertNull("Not null", sn.getNull());
In the above example, test method t1 will get the wrong result and display a lot of information, as follows:
Running com.jut.SntestTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.156 sec <<< FAILURE!
t1(com.jut.SntestTest) Time elapsed: 0.025 sec <<< FAILURE!
org.junit.ComparisonFailure: AString != String expected:<[A]String> but was:<String>
at org.junit.Assert.assertEquals(Assert.java:125)
at com.jut.SntestTest.t1(SntestTest.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
But what I want to see is only the first line to the fourth line.So how can I turn the output into the following result?
Running com.jut.SntestTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.156 sec <<< FAILURE!
t1(com.jut.SntestTest) Time elapsed: 0.025 sec <<< FAILURE!
org.junit.ComparisonFailure: AString != String expected:<[A]String> but was:<String>
java maven junit junit4
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
When i ues JUnit to test some java function, It will output some results regardless of success or failure.But sometimes it Looks like a bunch of small ants, makes me dizzy.
Perhaps the original intention of generating this output is to make better debugging.
But if there are hundreds or thousands of test cases, the output may not be fully displayed in the console.
So, is there a way to trigger an action when the test fails, just write the failed content to a file or send it to a mailbox?
E.g:
Sntest.java
package com.jut;
public class Sntest
public String getString()
return "String";
public Object getNull()
return null;
SntestTest.java
package com.jut;
import org.junit.Assert;
import org.junit.Test;
import com.jut.Sntest;
public class SntestTest
@Test
public void t1()
Sntest sn = new Sntest();
String msg = sn.getString();
Assert.assertEquals("AString != String", "AString", msg);
@Test
public void t2()
Sntest sn = new Sntest();
Assert.assertNull("Not null", sn.getNull());
In the above example, test method t1 will get the wrong result and display a lot of information, as follows:
Running com.jut.SntestTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.156 sec <<< FAILURE!
t1(com.jut.SntestTest) Time elapsed: 0.025 sec <<< FAILURE!
org.junit.ComparisonFailure: AString != String expected:<[A]String> but was:<String>
at org.junit.Assert.assertEquals(Assert.java:125)
at com.jut.SntestTest.t1(SntestTest.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
But what I want to see is only the first line to the fourth line.So how can I turn the output into the following result?
Running com.jut.SntestTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.156 sec <<< FAILURE!
t1(com.jut.SntestTest) Time elapsed: 0.025 sec <<< FAILURE!
org.junit.ComparisonFailure: AString != String expected:<[A]String> but was:<String>
java maven junit junit4
When i ues JUnit to test some java function, It will output some results regardless of success or failure.But sometimes it Looks like a bunch of small ants, makes me dizzy.
Perhaps the original intention of generating this output is to make better debugging.
But if there are hundreds or thousands of test cases, the output may not be fully displayed in the console.
So, is there a way to trigger an action when the test fails, just write the failed content to a file or send it to a mailbox?
E.g:
Sntest.java
package com.jut;
public class Sntest
public String getString()
return "String";
public Object getNull()
return null;
SntestTest.java
package com.jut;
import org.junit.Assert;
import org.junit.Test;
import com.jut.Sntest;
public class SntestTest
@Test
public void t1()
Sntest sn = new Sntest();
String msg = sn.getString();
Assert.assertEquals("AString != String", "AString", msg);
@Test
public void t2()
Sntest sn = new Sntest();
Assert.assertNull("Not null", sn.getNull());
In the above example, test method t1 will get the wrong result and display a lot of information, as follows:
Running com.jut.SntestTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.156 sec <<< FAILURE!
t1(com.jut.SntestTest) Time elapsed: 0.025 sec <<< FAILURE!
org.junit.ComparisonFailure: AString != String expected:<[A]String> but was:<String>
at org.junit.Assert.assertEquals(Assert.java:125)
at com.jut.SntestTest.t1(SntestTest.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
But what I want to see is only the first line to the fourth line.So how can I turn the output into the following result?
Running com.jut.SntestTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.156 sec <<< FAILURE!
t1(com.jut.SntestTest) Time elapsed: 0.025 sec <<< FAILURE!
org.junit.ComparisonFailure: AString != String expected:<[A]String> but was:<String>
java maven junit junit4
java maven junit junit4
edited Nov 9 at 3:15
asked Nov 9 at 2:50
时间只会一直走
14518
14518
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
i'm afraid it can't change to what you want. it is just a call stack which helps you to locate the problem
So, is there any way to capture the test cases that failed the test, because if there are many test cases, it is likely that they will not be fully displayed.
– 时间只会一直走
Nov 9 at 3:18
¿¿ 它本来就只捕捉失败的case
– J.Doe
Nov 9 at 4:00
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
i'm afraid it can't change to what you want. it is just a call stack which helps you to locate the problem
So, is there any way to capture the test cases that failed the test, because if there are many test cases, it is likely that they will not be fully displayed.
– 时间只会一直走
Nov 9 at 3:18
¿¿ 它本来就只捕捉失败的case
– J.Doe
Nov 9 at 4:00
add a comment |
up vote
0
down vote
i'm afraid it can't change to what you want. it is just a call stack which helps you to locate the problem
So, is there any way to capture the test cases that failed the test, because if there are many test cases, it is likely that they will not be fully displayed.
– 时间只会一直走
Nov 9 at 3:18
¿¿ 它本来就只捕捉失败的case
– J.Doe
Nov 9 at 4:00
add a comment |
up vote
0
down vote
up vote
0
down vote
i'm afraid it can't change to what you want. it is just a call stack which helps you to locate the problem
i'm afraid it can't change to what you want. it is just a call stack which helps you to locate the problem
answered Nov 9 at 3:03
J.Doe
263
263
So, is there any way to capture the test cases that failed the test, because if there are many test cases, it is likely that they will not be fully displayed.
– 时间只会一直走
Nov 9 at 3:18
¿¿ 它本来就只捕捉失败的case
– J.Doe
Nov 9 at 4:00
add a comment |
So, is there any way to capture the test cases that failed the test, because if there are many test cases, it is likely that they will not be fully displayed.
– 时间只会一直走
Nov 9 at 3:18
¿¿ 它本来就只捕捉失败的case
– J.Doe
Nov 9 at 4:00
So, is there any way to capture the test cases that failed the test, because if there are many test cases, it is likely that they will not be fully displayed.
– 时间只会一直走
Nov 9 at 3:18
So, is there any way to capture the test cases that failed the test, because if there are many test cases, it is likely that they will not be fully displayed.
– 时间只会一直走
Nov 9 at 3:18
¿¿ 它本来就只捕捉失败的case
– J.Doe
Nov 9 at 4:00
¿¿ 它本来就只捕捉失败的case
– J.Doe
Nov 9 at 4:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219161%2fhow-do-i-customize-how-i-display-junit-test-results%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown