ksylva / PDL_2020-2021_GR6

Wikipedia Matrix
0 stars 0 forks source link

TestParserWikiText : testParseWikiTextNbLign5 #9

Closed ksylva closed 3 years ago

ksylva commented 3 years ago

java.lang.AssertionError: We should have 13 rows expected:<13> but was:<0> at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.failNotEquals(Assert.java:834) at org.junit.Assert.assertEquals(Assert.java:645) at testsProjet.TestParserWikiText.testParseWikiTextNbLign5(TestParserWikiText.java:179) 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:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 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)

bene18 commented 3 years ago

The test method "testParseWikiTextNbLign5" works well. The problem lies in the URL passed as a parameter to the parser. Here is the url used in the method in question: https://en.wikipedia.org/w/index.php?title=Comparison_of_DEX_software&action=edit

If you open this url in your browser, you may notice that it does not contain any wikitext code (see below):

image

The table extraction algorithm via wikitext (see the ParserWikiText.java class) relies on the wikitext code to identify the tables in the page, so it is normal that it finds 0 lines on this page since it does not contain any wikitext code.

To fix this problem, you just have to use in the test method(testParseWikiTextNbLign5) a url containing wikiText code.
Example:https://en.wikipedia.org/wiki/Comparison_of_S.M.A.R.T._tools This page contains a 12-line table and is also coded in wikitext. It can be used to run the test method "testParseWikiTextNbLign5" by adapting the code as follows:

replace the line urlWikiText = "https://en.wikipedia.org/w/index.php?title=Comparison_of_DEX_software&action=edit"; by urlWikiText="https://en.wikipedia.org/w/index.php?title=Comparison_of_S.M.A.R.T._tools&action=edit"; and assertEquals("We should have 13 rows", 13, nbRow); by assertEquals("We should have 12 rows", 12, nbRow);

in the test method "testParseWikiTextNbLign5";

Note: You will agree with me that the names of the test methods are not very meaningful (see explanation below):

testParseWikiTextNbLign5==> to test the calculation of the number of rows in a table.

Whether it's 4 or 5, the test method for line count calculation keeps the same principle which is to check that the line count calculation still works. So there is not much point in making a test method "testParseWikiTextNbLign5" and "testParseWikiTextNbLign4" since both play the same role.

We can discuss this in another issue to find more relevant names.