Racial violence ravaged many parts of South Africa again today, on the eve of special parliamentary elections that are expected to provide a crucial test of white voters' reactions to the continuing unrest.

Four blacks died in clashes in several parts of the country today, and at least a dozen were injured, including two boys aged 5 and 7 who were treated for shotgun wounds after police opened fire on a group of blacks near the shantytown of Crossroads, outside Cape Town.

A leader of the Zulu-based Inkatha movement was assassinated, in an incident that seemed to foreshadow a revival of the conflict between Inkatha and supporters of the more radical United Democratic Front that resulted in more than 80 deaths in Durban in August.

President Pieter W. Botha's government is worried that its failure to quell the unrest is going to cost it votes in Wednesday's special elections, which are for five vacant seats in the white-controlled central Parliament.

Botha's National Party is acutely sensitive to the danger of losing the ethnic Afrikaner base of its support to the breakaway Conservative and Herstigte (Reconstituted) National parties on its far right, and will regard any significant loss of votes to them as a sign that it is heading for trouble.

Observers believe this accounts to some extent for Botha's toughened stance in recent weeks, with several defiant statements directed toward the United States and other western countries.

Recent threats to take action against the media, particularly foreign correspondents, appear to be both a part of this and to reflect a feeling that if the reporting of the unrest can be subdued then the political and economic damage will become more containable.

The government has turned on the media with accusations that distorted reporting of the unrest is aggravating the crisis. Today four black reporters said they had been subjected to a night of police brutality in the strife-torn township of Soweto, where they live.

There has been no reduction in the level of violence around Cape Town since the extension of emergency regulations there Saturday, and a funeral rally of more than 1,500 people held today in defiance of the stringent decree seemed to indicate that the level of militancy in the black and mixed-race communities there has not lessened.

There was a further indication of the ineffectiveness of the government's attempts to stamp out the unrest with repressive methods when violence flared up again today in the western Transvaal town of Westonaria, where the emergency was lifted Thursday after three months.

Police reported that they had found the first victim of a "necklace" killing in Crossroads, near Cape Town. In this form of assassination used by extremist groups against blacks suspected of collaborating with the government, the victim's body is pulled through an automobile tire that is filled with gasoline and set on fire.

Fears of a revival of the Durban violence were raised when a member of the legislative assembly of the KwaZulu "tribal homeland," Francis Dlamini, 37, was shot dead early today. His young son was wounded in the shooting at their home in the township of Umlazi.

This followed the recent gasoline bombing of the Umlazi home of the Mxenge family who supported the United Democratic Front.

It was the gunning down of Victoria Mxenge, a civil rights lawyer, that triggered the August violence between the front and supporters of the Zulu group Inkatha.

The government is concerned about the election despite having a parliamentary majority of more than two-thirds and not having to face a general election for another four years. Most observers expect it to retain all five seats being contested. Yet it is anxious about the outcome because this is the first test of white reaction since the unrest began 15 months ago.

Both strongly segregationist parties to the right of Botha's are attacking the president for causing the unrest in the first place with his attempts at reforming the apartheid system, and with allowing it to continue because he is too worried about foreign criticism to stamp it out ruthlessly.

The deepening economic crisis that is resulting from the continuing unrest, and which many whites are feeling in the form of increased unemployment and rising prices, is being attributed to Botha's "liberalism" and "kowtowing to foreigners" by his far-rightist challengers.

The government has made its nervousness evident by routinely excluding reporters from the areas of major clashes with the threat of summary arrest and imprisonment under the emergency regulations.

Four black newsmen said they were subjected to several hours of police brutality in Soweto last night.

According to Aggrey Klaaste, news editor of the country's main daily for blacks, The Sowetan, four members of his paper's staff, were picked up by an Army patrol and were beaten and hit with rifle butts. Klaaste said police dogs were set on the journalists when they showed their press identity cards.

He said they were beaten and kicked, then dragged to an armored vehicle and made to lie on top of it while it was driven around until dawn. Afterward the men had to be treated by a doctor, Klaaste said.

A police spokesman said he could not comment on the case.